2 additional alternatives for you:
If you're using P3D or OPENGL renderers you can also just draw a quad and set each vertex color accordingly, like:
Code:size(400,400,P3D);
beginShape(QUAD);
fill(0);
vertex(0,0);
fill(0,0,255);
vertex(width,0);
vertex(width,height);
fill(0);
vertex(0,height);
endShape();
If you want to draw multicolor gradients, you could also give toxiclibs a go (for this next example to work you need to download toxiclibscore & colorutils, both from
here).
Code:import toxi.geom.*;
import toxi.color.*;
void setup() {
size(1000,100);
}
void draw() {
ColorGradient grad=new ColorGradient();
grad.addColorAt(0,TColor.BLACK);
grad.addColorAt(width,TColor.BLUE);
grad.addColorAt(mouseX,TColor.RED);
grad.addColorAt(width-mouseX,TColor.YELLOW);
ColorList l=grad.calcGradient(0,width);
int x=0;
for(Iterator i=l.iterator(); i.hasNext();) {
TColor c=(TColor)i.next();
stroke(c.toARGB());
line(x,0,x,height);
x++;
}
}