How can I return the 'random' variables (red, green, blue) after the while-loop? Without the while loop the random colours work. I tried to implement the 'smaller than 150' constraint, and can't figure out how to do it.
private static Color createRandomColor() {
/*
return a new random color. A color is created using three numbers between 0 and 255
Constraint your colors to the following:
- at least one value should be smaller than 150
*/
int red;
int green;
int blue;
boolean i = false;
while (i = false) {
red = random.nextInt(256);
green = random.nextInt(256);
blue = random.nextInt(256);
if (red < 150 || green < 150 || blue < 150) {
i = true;
}
}
Color color = new Color(red, green, blue);
return color; //Replace with your random color
}
Aucun commentaire:
Enregistrer un commentaire