I'm trying to make a color picker for my game so you can customize it to your liking. I have written this code to try and construct it: However, this causes a very bad image which is not complete. What have I done wrong?
Note: this gets called with an 80 by 80 greenfootImage
public GreenfootImage drawPicker(GreenfootImage g)
{
Color prev = new Color(0,0,0);
for(int x = 0; x < g.getWidth()/5; x++)
{
int drawx = x*5;
for(int y = 0; y < g.getHeight()/5; y++)
{
int[] y_s = {y*5, y*5, (y*5)+5, (y*5)+5};
int r = prev.getRed();
int b = prev.getBlue();
int g1 = prev.getGreen();
switch(color){
case 0: try{prev = new Color(r+8,b,g1);}catch(IllegalArgumentException e){color = 1; prev = new Color(0,b,g1);}
break;
case 1: try{prev = new Color(r,b+8,g1);}catch(IllegalArgumentException e){color = 2; prev = new Color(r,0,g1);}
break;
case 2: try{prev = new Color(r,b,g1+8);}catch(IllegalArgumentException e){color = 0; return g;}
break;
default: return g;
}
System.out.println(color);
g.setColor(prev);
g.fillPolygon(new int[]{drawx,drawx+5,drawx+5,drawx}, y_s, 4);
}
}
return g;
}
