Source of: Bouncing Ball Animation, by Qwen3 235B A22B Instruct 2507
34 lines, 5 of them comments ยท 292 tokens, written in 10 seconds for $0.0002
1 function setup() {
2 createCanvas(400, 400);
3 // Ball properties
4 ball = {
5 x: 200,
6 y: 200,
7 diameter: 50,
8 xSpeed: 3,
9 ySpeed: 2
10 };
11 }
12
13 function draw() {
14 // Clear the canvas
15 background(220);
16
17 // Update ball position
18 ball.x += ball.xSpeed;
19 ball.y += ball.ySpeed;
20
21 // Bounce off the edges
22 if (ball.x < ball.diameter/2 || ball.x > width - ball.diameter/2) {
23 ball.xSpeed *= -1;
24 }
25
26 if (ball.y < ball.diameter/2 || ball.y > height - ball.diameter/2) {
27 ball.ySpeed *= -1;
28 }
29
30 // Draw the ball
31 fill(255, 0, 0);
32 noStroke();
33 ellipse(ball.x, ball.y, ball.diameter);
34 }