p5实现一个密密麻麻的圆圈动画效果代码
代码语言:html
所属分类:动画
代码描述:p5实现一个密密麻麻的圆圈动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body { margin: 0; padding: 0; overflow: hidden; display: flex; justify-content: center; align-items: center; height: 100vh; } canvas{ border: 40px solid black; box-shadow: 7px 3px 22px 0px rgba(0,0,0,0.4), 2px 2px 4px 0px rgba(0,0,0,0.3); } </style> </head> <body> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/p5.0.10.2.js"></script> <script > const config ={ width: 600, //window.innerWidth, height: 600, //window.innerHeight, seed: 2, dpr: 1, minRadius: 10, maxRadius: 100, maxCircles: 500, maxAttempts: 500 } let circles = []; function createCircle() { let newCircle; let isValid = false; for (let tries = 0; tries < config.maxAttempts; tries++) { newCircle = { x: Math.floor(random(config.width)), y: Math.floor(random(config.height)), radius: config.minRadius, phase: random(0.8)//random(0, TAU), } if(checkCollision(newCircle)) continue; isValid = true; break; } if (!isValid) { return; } for (var radiusSize = config.minRadius; radiusSize < config.maxRadius; radiusSize++) { newCircle.radius = radiusSize; if (checkCollision(newCircle)) { newCircle.radius--; break; } } return(newCircle); } function checkCollision(c) { for (var i = 0; i < circles.length.........完整代码请登录后点击上方下载按钮下载查看
网友评论0