Generating random colors

  • Thread starter Hiche
  • Start date
  • #1
84
0

Main Question or Discussion Point

Code:
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.
 

Answers and Replies

  • #2
33,265
4,965

Related Threads on Generating random colors

  • Last Post
Replies
2
Views
1K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
7
Views
3K
Replies
9
Views
1K
  • Last Post
Replies
1
Views
7K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
3
Views
4K
Replies
2
Views
3K
Replies
1
Views
3K
Replies
14
Views
5K
Top