Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
html, body { margin: 0; overflow: hidden; }
JavaScript
// click to create branch let x = []; let y = []; let size = []; let angle = []; let randDir = []; let itsClosestIndex = []; let movement = []; let moveSpeed = []; let currentCount = 1; let maxCount = 200; function setup() { createCanvas(windowWidth, windowHeight); x[0] = width / 2; y[0] = height / 2; size[0] = 10; angle[0] = 0; randDir[0] = 0; itsClosestIndex[0] = 0; //setFrameRate(10); for(let i = 0; i < maxCount; i++) { movement[i] = random(0.1); moveSpeed[i] = random(0.001, 0.003); } } function draw() { background(50); if(currentCount < maxCount) { let newSize = random(10, 50); let newX = random(width); let newY = random(height); closestIndex = 0; closestDist = width; for(let i = 0; i < currentCount; i++) { let newDist = dist(newX, newY, x[i], y[i]); if(newDist < closestDist) { closestDist = newDist; //print(closestDist); closestIndex = i; } } //temp line to view where shape comes from //line(newX, newY, x[closestIndex], y[closestIndex]); let newAngle = atan2(newY - y[closestIndex], newX - x[closestIndex]); //print(newAngle); let newrandDir = int(random(2)); //print(newrandDir); x[currentCount] = x[closestIndex] + cos(newAngle) * (size[closestIndex]/4 + newSize/4); y[currentCount] = y[closestIndex] + sin(newAngle) * (size[closestIndex]/4 + newSize/4); size[currentCount] = newSize; angle[currentCount] = newAngle; randDir[currentCount] = newrandDir; itsClosestIndex[currentCount] = closestIndex; currentCount++; } // draw the things for(let i = 0; i < currentCount; i++) { movement[i]+=moveSpeed[i]; if(movement[i] > .1 || movement[i] < 0) { moveSpeed[i]*=-1; } //print(movement[i]); strokeWeight(2); stroke(240, 100); line(x[i],y[i], x[itsClosestIndex[i]], y[itsClosestIndex[i]]); strokeWeight(1); fill(i*2, i*6, i, 100); drawLeafthing(x[i], y[i], size[i]/2, size[i], angle[i]+(PI*randDir[i]), movement[i]); } } function reset() { currentCount = 1; x[0] = mouseX; y[0] = mouseY; } function mousePressed() { reset(); } function drawLeafthing(x, y, width, height, direction, movement) { push(); translate(x, y); rotate(direction+movement); beginShape(); curveVertex(0, 0); //starting point curveVertex(0, 0); curveVertex(width/2, height/2); curveVertex(0, height); curveVertex(-width/2, height/2); endShape(CLOSE); pop(); }
粒子
时间
文字
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号