I'm making an app for generating fractals and I'm stuck on one thing. The program asks for two colors: one for the background, and one for the fractal. So I made an enum of colors:
public class Property {
public enum Color {
WHITE(new java.awt.Color(255, 255, 255).getRGB()),
BLACK(new java.awt.Color(0, 0, 0).getRGB()),
BLUE(new java.awt.Color(110, 124, 255).getRGB()),
GREEN(new java.awt.Color(121, 206, 30).getRGB()),
RED(new java.awt.Color(255, 58, 36).getRGB()),
YELLOW(new java.awt.Color(254, 255, 57).getRGB()),
ORANGE(new java.awt.Color(255, 133, 46).getRGB()),
PURPLE(new java.awt.Color(206, 27, 255).getRGB()),
PINK(new java.awt.Color(255, 40, 166).getRGB()),
RANDOM(Utils.randomColor()),
@Override
public String toString() {
return this.name().toLowerCase();
}
private int color;
Color(int color) {
this.color = color;
}
public int getRGB() {
return this.color;
}
}
}
The randomColor()
method looks like this:
public class Utils {
private static final Random RANDOM = new Random();
public static int randomColor() {
int r = RANDOM.nextInt(256);
int g = RANDOM.nextInt(256);
int b = RANDOM.nextInt(256);
return new java.awt.Color(r, g, b).getRGB();
}
}
But I noticed that the random color is actually created only once, and so both colors are the same which obviously is not a desired output. How can I make this generate two different colors each time the Property.Color.RANDOM
is called?
Aucun commentaire:
Enregistrer un commentaire