69 lines, no comments ยท 1,318 tokens, written in 17 seconds for $0.028


 1  let particles = [];
 2  let zoff = 0;
 3  const COUNT = 1400;
 4  
 5  function setup() {
 6    createCanvas(windowWidth, windowHeight);
 7    colorMode(HSB, 360, 100, 100, 100);
 8    background(230, 40, 8);
 9    for (let i = 0; i < COUNT; i++) particles.push(newParticle());
10  }
11  
12  function newParticle() {
13    return {
14      x: random(width),
15      y: random(height),
16      hue: random(170, 320),
17      speed: random(0.8, 2.2),
18      life: random(80, 400)
19    };
20  }
21  
22  function draw() {
23    noStroke();
24    fill(230, 40, 8, 5);
25    rect(0, 0, width, height);
26  
27    strokeWeight(1.2);
28    for (let p of particles) {
29      let a = noise(p.x * 0.0025, p.y * 0.0025, zoff) * TWO_PI * 2.5;
30      let vx = cos(a) * p.speed;
31      let vy = sin(a) * p.speed;
32  
33      let dx = p.x - mouseX;
34      let dy = p.y - mouseY;
35      let d2 = dx * dx + dy * dy;
36      if (d2 < 22500 && d2 > 1) {
37        let d = sqrt(d2);
38        let f = (150 - d) / 150 * 2;
39        vx += (-dy / d) * f;
40        vy += (dx / d) * f;
41      }
42  
43      let nx = p.x + vx;
44      let ny = p.y + vy;
45      let h = (p.hue + frameCount * 0.15) % 360;
46      stroke(h, 65, 100, 35);
47      line(p.x, p.y, nx, ny);
48      p.x = nx;
49      p.y = ny;
50      p.life--;
51  
52      if (p.life < 0 || p.x < 0 || p.x > width || p.y < 0 || p.y > height) {
53        Object.assign(p, newParticle());
54      }
55    }
56    zoff += 0.0025;
57  }
58  
59  function mousePressed() {
60    noiseSeed(floor(random(100000)));
61    background(230, 40, 8);
62    for (let p of particles) Object.assign(p, newParticle());
63  }
64  
65  function windowResized() {
66    resizeCanvas(windowWidth, windowHeight);
67    background(230, 40, 8);
68  }
69