Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
* { margin:0; padding:0; } html, body { width:100%; height:100%; overflow: hidden; background:black;} canvas { display:block; } #controls { z-index: 2; margin: 20px; position: absolute; top: 0; left: 0; color: white; }
JavaScript
let walkingSpeed = .5; let noiseSpeed = .4*walkingSpeed; let dirIncr = .01*walkingSpeed; let changeChance = .05*walkingSpeed; let angleChance = .01*walkingSpeed; let ribbonWidth = 200; let angleIncr = .01*walkingSpeed; let noiseScale = .02; let noiseHeight = 200; let hueShift = .001*walkingSpeed; let steps = 0; let stepsPerFrame = 20; let maxSteps = 5000; let numRibbons = 5; class Walker{ constructor(x, y, hue){ this.x = x; this.y = y; this.z = 0; this.dir = random(TAU); this.dirMod = random() < .5 ? 1 : -1; this.angleMod = random() < .5 ? 1 : -1; this.angle = random(-PI, PI); this.hue = hue; this.hueMod = 0; } update(){ this.x += cos(this.dir)*walkingSpeed; this.y += sin(this.dir)*walkingSpeed; this.dir += this.dirMod*dirIncr; if (random() < changeChance){ this.dirMod = random() < .5 ? 1 : -1; } if (random() < angleChance){ this.angleMod = random() < .5 ? 1 : -1; } this.hueMod += random(-hueShift, hueShift); this.hueMod = constrain(this.hueMod, -.1, .1); this.angle += this.angleMod*angleIncr; this.angle = constrain(this.angle, -PI, PI); this.z += noiseSpeed; } render(){ let hue = this.hue + this.hueMod; if (hue < 0) hue += 1; if (hue > 1) hue -= 1; push(); translate(this.x, this.y); rotate(this.angle + this.dir); translate(0, -ribbonWidth/2); beginShape(); stroke(hue, 1, 1, walkingSpeed/10); // strokeWeight(walkingSpeed/10); noFill(); for (let i = 0; i < ribbonWidth; i++){ let n = noise(i*noiseScale, this.z*noiseScale); n -= .5; n *= noiseHeight; vertex(n, i); } endShape(); pop(); } } function setup (){ pixelDensity(1); createCanvas(); blendMode(ADD); colorMode(HSB, 1, 1, 1); windowResized(); } let walkers; function init(){ clear(); background(0); steps = 0; walkers = []; let hue = random(); for (let i = 0; i < numRibbons; i++){ walkers.push(new Walker(random(width), random(height), hue + random(-.1, .1))); } } function draw(){ if(steps < maxSteps){ for (let i = 0; i < stepsPerFrame; i++){ walkers.map(w =>{ w.update(); w.render(); }) steps++; } } } function mousePressed(){init();} function windowResized(){ resizeCanvas(windowWidth, windowHeight); init(); }
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>canvas丝带-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号