65 lines, no comments ยท 1,820 tokens, written in 21 seconds for $0.094


 1  let particles = [];
 2  const NUM = 1200;
 3  let zoff = 0;
 4  let palette;
 5  
 6  function setup() {
 7    createCanvas(windowWidth, windowHeight);
 8    colorMode(HSB, 360, 100, 100, 100);
 9    background(230, 30, 8);
10    pickPalette();
11    for (let i = 0; i < NUM; i++) {
12      particles.push(makeParticle());
13    }
14  }
15  
16  function pickPalette() {
17    const h = random(360);
18    palette = [h, (h + 40 + random(60)) % 360];
19  }
20  
21  function makeParticle() {
22    return {
23      pos: createVector(random(width), random(height)),
24      vel: createVector(0, 0),
25      hue: lerp(palette[0], palette[1], random()),
26      life: random(100, 400),
27      speed: random(0.6, 1.8)
28    };
29  }
30  
31  function draw() {
32    noStroke();
33    fill(230, 30, 8, 3);
34    rect(0, 0, width, height);
35    const sc = 0.0025;
36    strokeWeight(1.2);
37    for (let p of particles) {
38      const n = noise(p.pos.x * sc, p.pos.y * sc, zoff);
39      const angle = n * TWO_PI * 2;
40      const acc = p5.Vector.fromAngle(angle).mult(0.25);
41      p.vel.add(acc).limit(p.speed);
42      const px = p.pos.x;
43      const py = p.pos.y;
44      p.pos.add(p.vel);
45      stroke(p.hue, 60, 95, 40);
46      line(px, py, p.pos.x, p.pos.y);
47      p.life--;
48      if (p.life <= 0 || p.pos.x < 0 || p.pos.x > width || p.pos.y < 0 || p.pos.y > height) {
49        Object.assign(p, makeParticle());
50      }
51    }
52    zoff += 0.0015;
53  }
54  
55  function mousePressed() {
56    pickPalette();
57    background(230, 30, 8);
58    particles = [];
59    for (let i = 0; i < NUM; i++) particles.push(makeParticle());
60  }
61  
62  function windowResized() {
63    resizeCanvas(windowWidth, windowHeight);
64    background(230, 30, 8);
65  }