Source of: Flowing Particle River, by Claude Opus 4.5
68 lines, no comments ยท 759 tokens, written in 11 seconds for $0.020
1 let particles = [];
2 let numParticles = 500;
3 let noiseScale = 0.01;
4 let hueOffset = 0;
5
6 function setup() {
7 createCanvas(windowWidth, windowHeight);
8 colorMode(HSB, 360, 100, 100, 100);
9 background(0, 0, 10);
10
11 for (let i = 0; i < numParticles; i++) {
12 particles.push(new Particle());
13 }
14 }
15
16 function draw() {
17 background(0, 0, 10, 5);
18 hueOffset += 0.5;
19
20 for (let p of particles) {
21 p.update();
22 p.display();
23 p.edges();
24 }
25 }
26
27 class Particle {
28 constructor() {
29 this.pos = createVector(random(width), random(height));
30 this.vel = createVector(0, 0);
31 this.acc = createVector(0, 0);
32 this.maxSpeed = 3;
33 this.hue = random(360);
34 this.size = random(2, 5);
35 }
36
37 update() {
38 let angle = noise(this.pos.x * noiseScale, this.pos.y * noiseScale, frameCount * 0.005) * TWO_PI * 4;
39 let force = p5.Vector.fromAngle(angle);
40 force.mult(0.5);
41 this.acc.add(force);
42
43 this.vel.add(this.acc);
44 this.vel.limit(this.maxSpeed);
45 this.pos.add(this.vel);
46 this.acc.mult(0);
47
48 this.hue = (noise(this.pos.x * 0.005, this.pos.y * 0.005) * 180 + hueOffset) % 360;
49 }
50
51 display() {
52 noStroke();
53 fill(this.hue, 80, 90, 60);
54 ellipse(this.pos.x, this.pos.y, this.size);
55 }
56
57 edges() {
58 if (this.pos.x > width) this.pos.x = 0;
59 if (this.pos.x < 0) this.pos.x = width;
60 if (this.pos.y > height) this.pos.y = 0;
61 if (this.pos.y < 0) this.pos.y = height;
62 }
63 }
64
65 function windowResized() {
66 resizeCanvas(windowWidth, windowHeight);
67 background(0, 0, 10);
68 }