61 lines, no comments ยท 1,425 tokens, written in 10 seconds for $0.015


 1  let particles = [];
 2  
 3  function setup() {
 4    createCanvas(windowWidth, windowHeight);
 5    colorMode(HSB, 360, 100, 100, 100);
 6    background(0, 0, 5);
 7    for (let i = 0; i < 1500; i++) {
 8      particles.push(new Particle());
 9    }
10  }
11  
12  class Particle {
13    constructor() {
14      this.reset();
15    }
16    reset() {
17      this.x = random(width);
18      this.y = random(height);
19      this.life = random(100, 300);
20    }
21    update() {
22      let a = noise(this.x * 0.002, this.y * 0.002, frameCount * 0.002) * TWO_PI * 2;
23      let px = this.x;
24      let py = this.y;
25      this.x += cos(a) * 1.5;
26      this.y += sin(a) * 1.5;
27      let dx = this.x - mouseX;
28      let dy = this.y - mouseY;
29      let d = sqrt(dx * dx + dy * dy);
30      if (d < 150 && d > 0) {
31        let f = (150 - d) / 150;
32        this.x += (dx / d) * f * 4;
33        this.y += (dy / d) * f * 4;
34      }
35      stroke((degrees(a) * 0.5 + frameCount * 0.3) % 360, 80, 100, 25);
36      strokeWeight(1.2);
37      line(px, py, this.x, this.y);
38      this.life--;
39      if (this.life < 0 || this.x < 0 || this.x > width || this.y < 0 || this.y > height) {
40        this.reset();
41      }
42    }
43  }
44  
45  function draw() {
46    noStroke();
47    fill(0, 0, 5, 4);
48    rect(0, 0, width, height);
49    for (let p of particles) {
50      p.update();
51    }
52  }
53  
54  function mousePressed() {
55    background(0, 0, 5);
56  }
57  
58  function windowResized() {
59    resizeCanvas(windowWidth, windowHeight);
60    background(0, 0, 5);
61  }