46 lines, no comments ยท 2,545 tokens, written in 12 seconds for $0.0097


 1  let particles = [];
 2  const numParticles = 800;
 3  let noiseScale = 0.008;
 4  
 5  function setup() {
 6    createCanvas(windowWidth, windowHeight);
 7    colorMode(HSB, 360, 100, 100, 1);
 8    for (let i = 0; i < numParticles; i++) {
 9      particles.push(createVector(random(width), random(height)));
10    }
11    background(0);
12  }
13  
14  function draw() {
15    background(0, 0, 0, 0.05);
16    strokeWeight(2);
17    let t = frameCount * 0.005;
18    for (let i = 0; i < particles.length; i++) {
19      let p = particles[i];
20      let n = noise(p.x * noiseScale, p.y * noiseScale, t);
21      let angle = n * TWO_PI * 4;
22      let v = p5.Vector.fromAngle(angle);
23      v.mult(2);
24      let d = dist(mouseX, mouseY, p.x, p.y);
25      if (d < 150) {
26        let push = createVector(p.x - mouseX, p.y - mouseY);
27        push.normalize();
28        push.mult(map(d, 0, 150, 6, 0));
29        v.add(push);
30      }
31      let prev = p.copy();
32      p.add(v);
33      let hueVal = (degrees(angle) + frameCount * 0.5) % 360;
34      stroke(hueVal, 80, 100, 0.6);
35      line(prev.x, prev.y, p.x, p.y);
36      if (p.x < 0) { p.x = width; prev.x = width; }
37      if (p.x > width) { p.x = 0; prev.x = 0; }
38      if (p.y < 0) { p.y = height; prev.y = height; }
39      if (p.y > height) { p.y = 0; prev.y = 0; }
40    }
41  }
42  
43  function windowResized() {
44    resizeCanvas(windowWidth, windowHeight);
45    background(0);
46  }