Generating random colors

  • Thread starter Hiche
  • Start date
  • #1
Hiche
84
0
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
36,194
8,180

Suggested for: Generating random colors

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