Source of: Bouncing Ball, by GPT-4
32 lines, no comments ยท 270 tokens, written in 2 seconds for $0.020
1 let x, y;
2 let xSpeed, ySpeed;
3 let ballColor;
4
5 function setup() {
6 createCanvas(400, 400);
7 x = random(width);
8 y = random(height);
9 xSpeed = random(2, 5);
10 ySpeed = random(2, 5);
11 ballColor = color(random(255), random(255), random(255));
12 }
13
14 function draw() {
15 background(0);
16 fill(ballColor);
17 noStroke();
18 ellipse(x, y, 30, 30);
19
20 x += xSpeed;
21 y += ySpeed;
22
23 if (x < 15 || x > width - 15) {
24 xSpeed *= -1;
25 ballColor = color(random(255), random(255), random(255));
26 }
27
28 if (y < 15 || y > height - 15) {
29 ySpeed *= -1;
30 ballColor = color(random(255), random(255), random(255));
31 }
32 }