lundi 29 février 2016

Fill Each Square With A Random Color

I am trying to fill the whole screen with squares, each one filled with a different color. I am able to generate the entire screen full of squares, but I cannot get them to be a random color. Here is what I have so far:

import java.util.Random;

public class RGBRandom
{
  public static void main(String[] args)
{
StdDraw.setScale(0, 100);

for (int x = 0; x <= 100; x++)
{     
  for (int y = 0; y <= 100; y++)
  {
    int r = (int)Math.random()*256;

    int g = (int)Math.random()*256;

    int b = (int)Math.random()*256;

    StdDraw.setPenColor(r, g, b);
    StdDraw.filledSquare(x, y, 0.5);
  }
} 
}
}




Aucun commentaire:

Enregistrer un commentaire