69 lines, no comments ยท 1,648 tokens, written in 19 seconds for $0.034


 1  let particles = [];
 2  let zoff = 0;
 3  const NUM = 1500;
 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 < NUM; i++) particles.push(new Particle());
10  }
11  
12  function draw() {
13    noStroke();
14    fill(230, 40, 8, 4);
15    rect(0, 0, width, height);
16    for (const p of particles) {
17      p.update();
18      p.show();
19    }
20    zoff += 0.003;
21  }
22  
23  class Particle {
24    constructor() {
25      this.reset();
26    }
27    reset() {
28      this.pos = createVector(random(width), random(height));
29      this.prev = this.pos.copy();
30      this.life = random(100, 300);
31      this.baseHue = random(-30, 60);
32      this.speed = random(1, 2.2);
33    }
34    update() {
35      const a = noise(this.pos.x * 0.003, this.pos.y * 0.003, zoff) * TWO_PI * 3;
36      const v = p5.Vector.fromAngle(a).mult(this.speed);
37      const d = dist(mouseX, mouseY, this.pos.x, this.pos.y);
38      if (d < 150 && d > 0.01) {
39        const push = p5.Vector.sub(this.pos, createVector(mouseX, mouseY));
40        push.setMag((150 - d) * 0.03);
41        v.add(push);
42      }
43      this.prev.set(this.pos);
44      this.pos.add(v);
45      this.life--;
46      if (this.life < 0 || this.pos.x < 0 || this.pos.x > width || this.pos.y < 0 || this.pos.y > height) {
47        this.reset();
48      }
49    }
50    show() {
51      const h = (200 + this.baseHue + frameCount * 0.15) % 360;
52      stroke(h, 70, 100, 35);
53      strokeWeight(1.2);
54      line(this.prev.x, this.prev.y, this.pos.x, this.pos.y);
55    }
56  }
57  
58  function mousePressed() {
59    noiseSeed(floor(random(100000)));
60    background(230, 40, 8);
61    for (const p of particles) p.reset();
62  }
63  
64  function windowResized() {
65    resizeCanvas(windowWidth, windowHeight);
66    background(230, 40, 8);
67    for (const p of particles) p.reset();
68  }
69