# Thread: [SOLVED] Expected Range: Red Green Blue

1. Senior Member
Join Date
Jan 2009
Location
CA, USA
Posts
271
Rep Power
8

## [SOLVED] Expected Range: Red Green Blue

I get the following error:

Exception in thread "AWT-EventQueue-1" java.lang.IllegalArgumentException: Color parameter outside of expected range: Red Green Blue

However, from what I've done I do not see how.
Take R (R, G, and B work the same way here). Regardless of what it becomes, I use R % 256, so the value should be between 0 and 255 (inclusive). How then is this value outside of the expected range (which is 0 to 255, right?)?

Java Code:
```for(int x = 0; x < WIDTH; x++)
{
for(int y = 0; y < HEIGHT; y++)
{
if(gen.nextInt(100) <= coverage)
{
int R = primColor.getRed(),
G = primColor.getGreen(),
B = primColor.getBlue();

R = (R + (gen.nextInt(2*range)-range)) % 256;
G = (G + (gen.nextInt(2*range)-range)) % 256;
B = (B + (gen.nextInt(2*range)-range)) % 256;

g.setColor(new Color(R, G, B)); //error here
g.fillRect(x, y, 1, 1);
}
}
}```
Last edited by AndrewM16921; 04-03-2009 at 07:48 PM.

2. Senior Member
Join Date
Jan 2009
Location
CA, USA
Posts
271
Rep Power
8
Oh, I figured out why lol.

Java Code:
```R = Math.abs((R + (gen.nextInt(2*range)-range)) % 256);
G = Math.abs((G + (gen.nextInt(2*range)-range)) % 256);
B = Math.abs((B + (gen.nextInt(2*range)-range)) % 256);```
There. ^_^

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•