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