Source of: Colorful Moving Circles, by GPT-4.1
36 lines, 1 of them comments ยท 382 tokens, written in 3 seconds for $0.0033
1 let circles = [];
2 let numCircles = 10;
3
4 function setup() {
5 createCanvas(600, 400);
6 for (let i = 0; i < numCircles; i++) {
7 circles.push({
8 x: random(width),
9 y: random(height),
10 r: random(30, 60),
11 dx: random(-3, 3),
12 dy: random(-3, 3),
13 color: [random(255), random(255), random(255)]
14 });
15 }
16 }
17
18 function draw() {
19 background(30, 36, 50, 60);
20 for (let c of circles) {
21 fill(c.color[0], c.color[1], c.color[2], 180);
22 noStroke();
23 ellipse(c.x, c.y, c.r);
24 c.x += c.dx;
25 c.y += c.dy;
26 // Bounce off walls
27 if (c.x - c.r/2 < 0 || c.x + c.r/2 > width) {
28 c.dx *= -1;
29 c.color = [random(255), random(255), random(255)];
30 }
31 if (c.y - c.r/2 < 0 || c.y + c.r/2 > height) {
32 c.dy *= -1;
33 c.color = [random(255), random(255), random(255)];
34 }
35 }
36 }