Source of: Bouncing Ball, by Gemini 2.5 Flash Lite
43 lines, 3 of them comments ยท 380 tokens, written in 2 seconds for $0.0002
1 let x, y;
2 let xSpeed, ySpeed;
3 let diameter;
4 let r, g, b;
5
6 function setup() {
7 createCanvas(400, 400);
8 diameter = 50;
9 x = width / 2;
10 y = height / 2;
11 xSpeed = 3;
12 ySpeed = 2;
13 r = random(255);
14 g = random(255);
15 b = random(255);
16 }
17
18 function draw() {
19 background(220);
20
21 // Move the ball
22 x += xSpeed;
23 y += ySpeed;
24
25 // Check for collisions with walls
26 if (x + diameter / 2 > width || x - diameter / 2 < 0) {
27 xSpeed *= -1;
28 r = random(255);
29 g = random(255);
30 b = random(255);
31 }
32 if (y + diameter / 2 > height || y - diameter / 2 < 0) {
33 ySpeed *= -1;
34 r = random(255);
35 g = random(255);
36 b = random(255);
37 }
38
39 // Draw the ball
40 fill(r, g, b);
41 noStroke();
42 ellipse(x, y, diameter, diameter);
43 }