60 lines, no comments ยท 814 tokens, written in 10 seconds for $0.0042


 1  let particles = [];
 2  let time = 0;
 3  let paletteOffset;
 4  
 5  function setup() {
 6    createCanvas(windowWidth, windowHeight);
 7    pixelDensity(1);
 8    colorMode(HSB, 360, 100, 100, 100);
 9    resetSketch();
10  }
11  
12  function resetSketch() {
13    background(225, 35, 5);
14    noiseSeed(floor(random(100000)));
15    paletteOffset = random(360);
16    time = 0;
17    particles = [];
18    const count = constrain(floor(width * height / 900), 350, 1800);
19    for (let i = 0; i < count; i++) {
20      particles.push({
21        x: random(width),
22        y: random(height),
23        speed: random(0.7, 2.5),
24        hue: random(-35, 35)
25      });
26    }
27  }
28  
29  function draw() {
30    background(225, 35, 5, 7);
31    strokeWeight(1);
32  
33    for (const p of particles) {
34      const angle = noise(p.x * 0.003, p.y * 0.003, time) * TWO_PI * 3;
35      const oldX = p.x;
36      const oldY = p.y;
37      p.x += cos(angle) * p.speed;
38      p.y += sin(angle) * p.speed;
39  
40      if (p.x < 0 || p.x > width || p.y < 0 || p.y > height) {
41        p.x = random(width);
42        p.y = random(height);
43        continue;
44      }
45  
46      const hue = (paletteOffset + p.hue + noise(p.x * 0.002, p.y * 0.002) * 100 + 360) % 360;
47      stroke(hue, 75, 100, 55);
48      line(oldX, oldY, p.x, p.y);
49    }
50    time += 0.002;
51  }
52  
53  function mousePressed() {
54    resetSketch();
55  }
56  
57  function windowResized() {
58    resizeCanvas(windowWidth, windowHeight);
59    resetSketch();
60  }