I have this code and i only get random greyscale colors.
All the answers i’ve found on the internet don’t work.
How do i do this?
color colorBall = color(0, 0, 0);
float xspeed = 5;
float yspeed = 4;
float circleX = 0;
float circleY = 0;
void setup() {
size(640, 360);
}
void draw() {
background(0);
// CIRCLE
displayBall();
movingBall();
bouncingBall();
}
void displayBall() {
fill(colorBall);
stroke(255);
ellipse(circleX, circleY, 32, 32);
}
void movingBall() {
circleX = circleX + xspeed;
circleY = circleY + yspeed;
}
void bouncingBall() {
if (circleY > height || circleY < 0) {
yspeed = yspeed * -1;
colorBall = (int)random(255);
}
if (circleX > width || circleX < 0) {
xspeed = xspeed * -1;
colorBall = (int)random(255);
}
}