How to make a random RGB color value for variable?

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);
  }
}

Hey buddy, don’t forget to indent your code next time. Use the </> feature in the text box so that we can read your code better.
The issue here is that you’re assigning a random value just to the greyscale channel. This will always happen when you assign one int number to a color variable. Try assigning random values to each channel of the color variable.

color myRandomColor = color(random(255), random(255), random(255));
1 Like

colorBall = (color) random(#000000);

1 Like

The indenting doesn’t work when i edit my post now…
Can you maybe tell me how to do it?
Also the line of code gives this error message:

44

“The value of the local variable “colorBall” is not used”

colorBall = (color) random(#000000); works

Thanks you both!