js实现风吹动画
代码语言:html
所属分类:动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> html, body { margin: 0; padding: 0; } body { overflow: hidden; width: 100vw; height: 100vh; display: flex; justify-content: center; align-items: center; } </style> </head> <body translate="no"> <canvas class="js-canvas"></canvas> <script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/simplex-noise.min.js"></script> <script> const simplex = new SimplexNoise(); const getAngleBetween = (vec1, vec2) => Math.atan2(vec2.y - vec1.y, vec2.x - vec1.x); const randomArrayValue = arr => arr[Math.floor(Math.random() * arr.length)]; const palettes = [ ['#f65c78', '#ffd271', '#fff3af', '#c3f584'], ['#111d5e', '#b21f66', '#fe346e', '#ffbd69'], ['#36b5b0', '#9dd8c8', '#f09595', '#fcf5b0'], ['#015668', '#263f44', '#ffd369', '#fff1cf']]; const canvas = document.querySelector('.js-canvas'); const ctx = canvas.getContext('2d'); const TAU = Math.PI * 2; const width = window.innerWidth; const height = window.innerHeight; const midX = width >> 1; const midY = height >> 1; canvas.width = width; canvas.height = height; let phase = 0; let phaseSpeed = 0.001; let noiseAmp = 0.08; let palette = []; let trails = []; const numTrails = 400; const generate = ({ x = midX, y = midY } = {}) => { noiseAmp = 0.08; palette = randomArrayValue(palettes); trails = []; for (let i = 0; i < numTrails; i++) { const spacing = 0.5; const lineWidth = 3 + Math.random() * 3; const velocity = 10 + Math.random() * 10; const angle = TAU / numTrails * i; const numPoints = 20 + Math.random() * 5; const points = []; const life = 1; const color = randomArrayValue(palette); for (let q = 0; q < numPoints; q++) { points.push({ x, y .........完整代码请登录后点击上方下载按钮下载查看
网友评论0