# [SOLVED] Expected Range: Red Green Blue

Printable View

• 04-03-2009, 07:40 PM
AndrewM16921
[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?)?

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);                 }         } }```
• 04-03-2009, 07:59 PM
AndrewM16921
Oh, I figured out why lol.

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. ^_^