57 lines, 3 of them comments ยท 846 tokens, written in 6 seconds for $0.0070


 1  let particles = [];
 2  const NUM = 150;
 3  let center;
 4  
 5  function setup() {
 6    createCanvas(windowWidth, windowHeight);
 7    colorMode(HSB, 360, 100, 100, 100);
 8    noStroke();
 9    center = createVector(width / 2, height / 2);
10    for (let i = 0; i < NUM; i++) {
11      particles.push(new Particle());
12    }
13    background(0);
14  }
15  
16  function draw() {
17    // Fade the previous frame slightly to create trails
18    fill(0, 0, 0, 10);
19    rect(0, 0, width, height);
20  
21    // Ease the center toward the mouse
22    center.x = lerp(center.x, mouseX, 0.05);
23    center.y = lerp(center.y, mouseY, 0.05);
24  
25    blendMode(ADD);
26    particles.forEach(p => p.update());
27    blendMode(BLEND);
28  }
29  
30  class Particle {
31    constructor() {
32      this.reset();
33    }
34    reset() {
35      this.r = random(20, min(width, height) * 0.45);
36      this.angle = random(TWO_PI);
37      this.speed = random(-0.03, 0.03);
38      this.size = random(2, 6);
39      this.hue = random(360);
40    }
41    update() {
42      this.angle += this.speed;
43      let x = center.x + cos(this.angle) * this.r;
44      let y = center.y + sin(this.angle) * this.r;
45  
46      fill(this.hue, 80, 100, 60);
47      circle(x, y, this.size);
48  
49      // Occasionally respawn to keep things fresh
50      if (random() < 0.002) this.reset();
51    }
52  }
53  
54  function windowResized() {
55    resizeCanvas(windowWidth, windowHeight);
56    background(0);
57  }