Source of: Bouncing Color Orbs, by GPT-5.4
49 lines, 2 of them comments ยท 510 tokens, written in 8 seconds for $0.0079
1 let orbs = [];
2 const orbCount = 25;
3
4 function setup() {
5 createCanvas(windowWidth, windowHeight);
6 noStroke();
7 for (let i = 0; i < orbCount; i++) {
8 orbs.push({
9 x: random(width),
10 y: random(height),
11 vx: random(-2, 2),
12 vy: random(-2, 2),
13 r: random(8, 20),
14 c: color(random(100, 255), random(100, 255), random(100, 255), 220)
15 });
16 }
17 }
18
19 function draw() {
20 background(10, 15, 30, 40);
21
22 // Draw connection lines
23 for (let i = 0; i < orbs.length; i++) {
24 for (let j = i + 1; j < orbs.length; j++) {
25 const d = dist(orbs[i].x, orbs[i].y, orbs[j].x, orbs[j].y);
26 if (d < 140) {
27 stroke(255, map(d, 0, 140, 120, 0));
28 line(orbs[i].x, orbs[i].y, orbs[j].x, orbs[j].y);
29 }
30 }
31 }
32
33 // Update and draw orbs
34 noStroke();
35 for (let orb of orbs) {
36 orb.x += orb.vx;
37 orb.y += orb.vy;
38
39 if (orb.x < orb.r || orb.x > width - orb.r) orb.vx *= -1;
40 if (orb.y < orb.r || orb.y > height - orb.r) orb.vy *= -1;
41
42 fill(orb.c);
43 circle(orb.x, orb.y, orb.r * 2);
44 }
45 }
46
47 function windowResized() {
48 resizeCanvas(windowWidth, windowHeight);
49 }