Source of: Chromatic Currents, by GPT-6.1 Terra
80 lines, no comments ยท 963 tokens, written in 12 seconds for $0.0049
1 let particles = [];
2 const particleCount = 700;
3
4 function setup() {
5 createCanvas(windowWidth, windowHeight);
6 pixelDensity(1);
7 colorMode(HSB, 360, 100, 100, 100);
8 background(230, 35, 7);
9 for (let i = 0; i < particleCount; i++) {
10 particles.push(new Particle());
11 }
12 }
13
14 function draw() {
15 noStroke();
16 fill(230, 35, 7, 5);
17 rect(0, 0, width, height);
18
19 for (const particle of particles) {
20 particle.update();
21 particle.display();
22 }
23 }
24
25 function mouseClicked() {
26 background(230, 35, 7);
27 for (const particle of particles) particle.reset();
28 }
29
30 function windowResized() {
31 resizeCanvas(windowWidth, windowHeight);
32 background(230, 35, 7);
33 for (const particle of particles) particle.reset();
34 }
35
36 class Particle {
37 constructor() {
38 this.reset();
39 }
40
41 reset() {
42 this.x = random(width);
43 this.y = random(height);
44 this.previousX = this.x;
45 this.previousY = this.y;
46 this.speed = random(1, 3);
47 this.hue = random(170, 320);
48 }
49
50 update() {
51 this.previousX = this.x;
52 this.previousY = this.y;
53
54 const angle = noise(this.x * 0.002, this.y * 0.002, frameCount * 0.002) * TWO_PI * 3;
55 let dx = cos(angle) * this.speed;
56 let dy = sin(angle) * this.speed;
57
58 if (mouseIsPressed) {
59 const distance = dist(this.x, this.y, mouseX, mouseY);
60 if (distance > 1 && distance < 250) {
61 const pull = map(distance, 0, 250, 2, 0);
62 dx += (mouseX - this.x) / distance * pull;
63 dy += (mouseY - this.y) / distance * pull;
64 }
65 }
66
67 this.x += dx;
68 this.y += dy;
69
70 if (this.x < 0 || this.x > width || this.y < 0 || this.y > height) {
71 this.reset();
72 }
73 }
74
75 display() {
76 stroke(this.hue, 75, 100, 55);
77 strokeWeight(1.2);
78 line(this.previousX, this.previousY, this.x, this.y);
79 }
80 }