Source of: Cursor Particle Swarm, by Grok 4.6
50 lines, no comments ยท 2,424 tokens, written in 35 seconds for $0.015
1 function setup() {
2 createCanvas(windowWidth, windowHeight);
3 colorMode(HSB, 360, 100, 100, 100);
4 noStroke();
5 }
6
7 let particles = [];
8
9 function draw() {
10 background(0, 12);
11 particles.push(new Particle(mouseX, mouseY));
12 if (particles.length > 120) {
13 particles.shift();
14 }
15 for (let p of particles) {
16 p.update();
17 p.show();
18 }
19 }
20
21 function windowResized() {
22 resizeCanvas(windowWidth, windowHeight);
23 }
24
25 class Particle {
26 constructor(x, y) {
27 this.pos = createVector(x + random(-8, 8), y + random(-8, 8));
28 this.vel = p5.Vector.random2D().mult(random(0.3, 1.8));
29 this.acc = createVector(0, 0);
30 this.hue = (frameCount * 1.5) % 360;
31 this.life = 100;
32 }
33
34 update() {
35 let mouse = createVector(mouseX, mouseY);
36 let force = p5.Vector.sub(mouse, this.pos);
37 force.setMag(0.04);
38 this.acc.add(force);
39 this.vel.add(this.acc);
40 this.vel.limit(2.5);
41 this.pos.add(this.vel);
42 this.acc.mult(0);
43 this.life -= 0.8;
44 }
45
46 show() {
47 fill(this.hue, 75, 95, this.life);
48 ellipse(this.pos.x, this.pos.y, 7);
49 }
50 }