I have created code to draw a random Oval with a random color and coordinate in a random part of a section of a plane that I have provided in swing every time my loop runs. Is there a simpler way to get these random values for the oval and if so what is it? Here is the code that I am using:
for(int i = 0; i <= 200; i++) {
double r = Math.random();
int k = (int)(r * 255);
double s = Math.random();
int l = (int)(s * 255);
double t = Math.random();
int m = (int)(t * 255);
g2d.setColor(new Color(k, l, m));
double p = Math.random();
int o = (int)(p * 550);
double x = Math.random();
int y = (int)(x * 500);
g2d.fillOval(250 + o, 250 + y, 30, 30);
}
Aucun commentaire:
Enregistrer un commentaire