33 lines, 4 of them comments ยท 284 tokens, written in 9 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: 4
10    };
11  }
12  
13  function draw() {
14    background(220);
15    
16    // Draw the ball
17    fill(255, 0, 0);
18    noStroke();
19    ellipse(ball.x, ball.y, ball.diameter, ball.diameter);
20    
21    // Move the ball
22    ball.x += ball.xSpeed;
23    ball.y += ball.ySpeed;
24    
25    // Bounce off the edges
26    if (ball.x < ball.diameter/2 || ball.x > width - ball.diameter/2) {
27      ball.xSpeed *= -1;
28    }
29    
30    if (ball.y < ball.diameter/2 || ball.y > height - ball.diameter/2) {
31      ball.ySpeed *= -1;
32    }
33  }