So I have to draw 4 squares and then 10 random squares inside of each of the squares with random x and y coordinates and they have to be symetrical and then draw the whole screen with them side by side. Each section(4 large squares is a section) has to have the same random squares and in the same color. I have gotten to the point where I can draw a single section but can't think of anything to make them be drawn over and over so they cover the whole screen with the same random squares and random colors. Hope you understood it. Here is what I have right now.
@Override
public void paint(Graphics g){
int a=100;
Random rand = new Random();
g.setColor(Color.black);
g.drawRect(50, 50, a, a);
g.drawRect(50+a, 50, a, a);
g.drawRect(50, 50+a, a, a);
g.drawRect(50+a, 50+a, a, a);
int r = rand.nextInt(a/2);
int rx = rand.nextInt(a/2)+50;
int ry = rand.nextInt(a/2)+50;
int rxsim = (2*a+50)-(rx-50)-r;
int rysim = (2*a+50)-(ry-50)-r;
g.setColor(new Color(rand.nextInt(255),rand.nextInt(255),rand.nextInt(255)));
g.fillRect(rx, ry, r, r);
g.fillRect(rxsim, ry, r, r);
g.fillRect(rx, rysim, r, r);
g.fillRect(rxsim, rysim, r, r);
}
Aucun commentaire:
Enregistrer un commentaire