Results 1 to 2 of 2
  1. #1
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    NJ, USA
    Posts
    263
    Rep Power
    6

    Default [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. #2
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    NJ, USA
    Posts
    263
    Rep Power
    6

    Default

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

Similar Threads

  1. Replies: 3
    Last Post: 08-24-2008, 01:51 PM
  2. Replies: 1
    Last Post: 08-07-2007, 06:13 AM
  3. Open Blue Lab 1.3.2
    By levent in forum Java Software
    Replies: 0
    Last Post: 08-01-2007, 04:22 PM
  4. Can I set a range in case statement?
    By christina in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 08:41 PM
  5. Open Blue Lab 1.2.10
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-19-2007, 08:08 AM

Posting Permissions

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