gsap模拟人头攒动的人群聚集动画效果
代码语言:html
所属分类:动画
代码描述:gsap模拟人头攒动的人群聚集动画效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> html, body { height: 100%; } body { margin: 0; } #canvas { width: 100%; height: 100%; } </style> </head> <body translate="no"> <canvas id="canvas"></canvas> <script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/gsap.3.2.4.js"></script> <script> console.clear() console.log('lsakdfalskjdflnksd') const config = { src: 'http://repo.bfw.wiki/bfwrepo/image/5e950a2225b53.png', rows: 15, cols: 7 } // UTILS const randomRange = (min, max) => min + Math.random() * (max - min) const randomIndex = (array) => randomRange(0, array.length) | 0 const removeFromArray = (array, i) => array.splice(i, 1)[0] const removeItemFromArray = (array, item) => removeFromArray(array, array.indexOf(item)) const removeRandomFromArray = (array) => removeFromArray(array, randomIndex(array)) const getRandomFromArray = (array) => ( array[randomIndex(array) | 0] ) // TWEEN FACTORIES const resetPeep = ({ stage, peep }) => { const direction = Math.random() > 0.5 ? 1 : -1 // using an ease function to skew random to lower values to help hide that peeps have no legs const offsetY = 100 - 250 * gsap.parseEase('power2.in')(Math.random()) const startY = stage.height - peep.height + offsetY let startX let endX if (direction === 1) { startX = -peep.width endX = stage.width peep.scaleX = 1 } else { startX = stage.width + peep.width endX = 0 peep.scaleX = -1 } peep.x = startX peep.y = startY peep.anchorY = startY return { startX, startY, endX } } const normalWalk = ({ peep, props }) => { const { startX, startY, endX } = props const xDuration = 10 const yDuration = 0.25 const tl = gsap.timeline() tl.timeScale(randomRange(0.5, 1.5)) tl.to(peep, { duration: xDuration, x: endX, ease: 'none' }, 0) tl.to(peep, { duration: yDuration, repeat: xDuration / yDuration, yoyo: true, y: startY - 10 }, 0) return tl } const walks = [ normalWalk, ] // CLASSES class Peep { constructor({ image, rect, }) { this.image = image this.setRect(rect) this.x = 0 this.y = 0 this.anchorY = 0 this.scaleX = 1 this.walk = null } setRect (rect) { this.rect = rect this.width = re.........完整代码请登录后点击上方下载按钮下载查看
网友评论0