Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Generating random colors

  1. Nov 19, 2011 #1
    Code (Text):
    import java.awt.Color;

    public class ChangingColor
    {  
        public static void main(String[] args)
        {
            while (true)
            {
                int R = (int) (Math.random() * 256);
                int G = (int) (Math.random() * 256);
                int B = (int) (Math.random() * 256);   
                Color randomColor = new Color(R, G, B);
               
                StdDraw.setPenColor(randomColor);
                StdDraw.filledSquare(.5, .5, .25);
                StdDraw.show(500);
            }
        }

    }
    Okay, this works. But is there another way to code this using only the StdDraw class? I used Color, but we haven't covered this a lot.
     
  2. jcsd
  3. Nov 21, 2011 #2

    Mark44

    Staff: Mentor

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Generating random colors
  1. Random # Generator (Replies: 2)

Loading...