Source of: Aurora Drift, by Grok 4.7
65 lines, no comments ยท 1,832 tokens, written in 16 seconds for $0.012
1 let particles = [];
2 const COUNT = 110;
3
4 function setup() {
5 createCanvas(windowWidth, windowHeight);
6 colorMode(HSB, 360, 100, 100, 100);
7 for (let i = 0; i < COUNT; i++) particles.push(new Particle());
8 }
9
10 function draw() {
11 background(232, 42, 7, 16);
12 for (let i = 0; i < particles.length; i++) {
13 const a = particles[i];
14 a.update();
15 for (let j = i + 1; j < particles.length; j++) {
16 const b = particles[j];
17 const d = dist(a.pos.x, a.pos.y, b.pos.x, b.pos.y);
18 if (d < 120) {
19 stroke((a.hue + b.hue) * 0.5, 55, 100, map(d, 0, 120, 38, 0));
20 strokeWeight(1);
21 line(a.pos.x, a.pos.y, b.pos.x, b.pos.y);
22 }
23 }
24 a.show();
25 }
26 }
27
28 class Particle {
29 constructor() {
30 this.pos = createVector(random(width), random(height));
31 this.vel = p5.Vector.random2D().mult(random(0.3, 1.2));
32 this.hue = random(160, 290);
33 this.r = random(2.5, 5.5);
34 }
35
36 update() {
37 const n = noise(this.pos.x * 0.0028, this.pos.y * 0.0028, frameCount * 0.004);
38 const ang = n * TWO_PI * 2;
39 this.vel.add(cos(ang) * 0.07, sin(ang) * 0.07);
40 const m = createVector(mouseX, mouseY);
41 const d = p5.Vector.dist(this.pos, m);
42 if (d < 150 && d > 0) {
43 this.vel.add(p5.Vector.sub(this.pos, m).setMag(map(d, 0, 150, 0.7, 0)));
44 }
45 this.vel.limit(2.1);
46 this.pos.add(this.vel);
47 if (this.pos.x < 0) this.pos.x = width;
48 if (this.pos.x > width) this.pos.x = 0;
49 if (this.pos.y < 0) this.pos.y = height;
50 if (this.pos.y > height) this.pos.y = 0;
51 }
52
53 show() {
54 noStroke();
55 fill(this.hue, 40, 100, 22);
56 circle(this.pos.x, this.pos.y, this.r * 4);
57 fill(this.hue, 65, 100, 92);
58 circle(this.pos.x, this.pos.y, this.r);
59 }
60 }
61
62 function windowResized() {
63 resizeCanvas(windowWidth, windowHeight);
64 }
65