Add sketch.js
Browse files
sketch.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
// Welcome to Visual Coding! 🎨
|
| 3 |
+
|
| 4 |
+
let x = 100;
|
| 5 |
+
let y = 200;
|
| 6 |
+
let speedX = 7;
|
| 7 |
+
let speedY = 2;
|
| 8 |
+
let ballSize = 50;
|
| 9 |
+
|
| 10 |
+
function setup() {
|
| 11 |
+
createCanvas(450, 500);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
function draw() {
|
| 16 |
+
// Create trail effect by drawing a semi-transparent background
|
| 17 |
+
background(50, 50, 50, 25);
|
| 18 |
+
|
| 19 |
+
// Update position
|
| 20 |
+
x += speedX;
|
| 21 |
+
y += speedY;
|
| 22 |
+
|
| 23 |
+
// Bounce off edges
|
| 24 |
+
if (x > width - ballSize/2 || x < ballSize/2) {
|
| 25 |
+
speedX *= -1;
|
| 26 |
+
}
|
| 27 |
+
if (y > height - ballSize/2 || y < ballSize/2) {
|
| 28 |
+
speedY *= -1;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
// Draw bouncing ball
|
| 32 |
+
fill(random(100, 255), random(100, 255), random(100, 255));
|
| 33 |
+
circle(x, y, ballSize);
|
| 34 |
+
|
| 35 |
+
// Add some sparkles
|
| 36 |
+
for (let i = 0; i < 3; i++) {
|
| 37 |
+
fill(255, 255, 255, 150);
|
| 38 |
+
circle(x + random(-30, 30), y + random(-30, 30), random(3, 8));
|
| 39 |
+
}
|
| 40 |
+
}
|