p5实现圆圈点连线鼠标点击交互旅行动画效果代码
代码语言:html
所属分类:动画
代码描述:p5实现圆圈点连线鼠标点击交互旅行动画效果代码
代码标签: p5 圆圈 点 连线 鼠标 点击 交互 旅行 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body { margin: 0; padding: 0; height: 100vh; overflow: hidden; display: flex; align-items: center; justify-content: center; background: black; } </style> </head> <body translate="no"> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/p5.1.8.0.js"></script> <script > // #wccchallenge - connection the dots //click to change let points = []; let nPoints = 100; let travelers = []; function setup() { createCanvas(windowWidth, windowHeight); background(0); cnt = 0; d = 15; p = { x: 0, y: 0 }; points.push(p); angleMode(DEGREES); c = 0; while (c < 2000) { r = random(-min(width, height) / 2.5); a = random(360); p = { x: r * cos(a), y: r * sin(a) }; c++; b = true; for (let i = 0; i < points.length; i++) { if (dist(p.x, p.y, points[i].x, points[i].y) < d) { b = false; } } if (b) { cnt++; points[cnt] = p; } } travelers[0] = { x: 0, y: 0, x1: 0, y1: 0, r: random(20, width / 4), centerX: 0, centerY: 0, a: 0, t: 0, speed: 0.5, d: 30 }; } function draw() { translate(width / 2, height / 2); background(0, 0, 0, 20); t = frameCount / 30; rotate(t); for (let i = 0; i < travelers.length; i++) { travelers[i].x = travelers[i].r * cos(travelers[i].a + travelers[i].t); travelers[i].y = travelers[i].r * sin(travelers[i].a + travelers[i].t); travelers[i].t += travelers[i].speed; } d2 .........完整代码请登录后点击上方下载按钮下载查看
网友评论0