-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
42 lines (36 loc) · 854 Bytes
/
sketch.js
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
42
let x, y, xspeed, yspeed, ballColor;
function setup() {
createCanvas(windowWidth, windowHeight);
x = width / 2;
y = height / 2;
xspeed = 5;
yspeed = 3;
ballColor = color(random(255), random(255), random(255));
}
function draw() {
background(220);
fill(ballColor);
ellipse(x, y, 50, 50);
x += xspeed;
y += yspeed;
if (x > width || x < 0) {
xspeed = -xspeed;
ballColor = color(random(255), random(255), random(255));
}
if (y > height || y < 0) {
yspeed = -yspeed;
ballColor = color(random(255), random(255), random(255));
}
// add text at the top of the canvas
fill(0);
textSize(24);
textAlign(CENTER);
text(
"Click to change the color - simple P5JS Webtoy for SWE",
windowWidth / 2,
50
);
}
function mousePressed() {
ballColor = color(random(255), random(255), random(255));
}