I'm new to Processing and I need to create a random color, but it returns an error.
int R = (int)(Math.random()*255);
int G = (int)(Math.random()*255);
int B = (int)(Math.random()*255);
color randomColor = new color(R,G,B);
The final line in this returns error on "int" Did I not write the last line properly?
The other answers don't realize that color
is a type in Processing.
Your problem is that you're trying to use a new color()
constructor, which doesn't exist. Try using the color()
function, like this:
color randomColor = color(R,G,B);
More info can be found in the reference.
Also note that Processing has its own random()
function that you should be using instead of directly calling Math.random()
yourself.
Edit: Turns out other people have been confused by this, and here is a discussion on implementing better error messages.