File size: 778 Bytes
66faed7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

// Welcome to Visual Coding! 🎨

let x = 100;
let y = 200;
let speedX = 7;
let speedY = 2;
let ballSize = 50;

function setup() {
  createCanvas(450, 500);
}


function draw() {
  // Create trail effect by drawing a semi-transparent background
  background(50, 50, 50, 25);
  
  // Update position
  x += speedX;
  y += speedY;
  
  // Bounce off edges
  if (x > width - ballSize/2 || x < ballSize/2) {
    speedX *= -1;
  }
  if (y > height - ballSize/2 || y < ballSize/2) {
    speedY *= -1;
  }
  
  // Draw bouncing ball
  fill(random(100, 255), random(100, 255), random(100, 255));
  circle(x, y, ballSize);
  
  // Add some sparkles
  for (let i = 0; i < 3; i++) {
    fill(255, 255, 255, 150);
    circle(x + random(-30, 30), y + random(-30, 30), random(3, 8));
  }
}