Gradient g; int[] currG; boolean inited; int[] buffer; int area; void setup() { size(200,200); inited=false; area=width*height; buffer=new int[area]; } void draw() { if (!inited) { initColors(); inited=true; } currG=g.calcGradient(max(mouseY*5,0),height); for(int y=0; y>16,b>>16,f)<<16 | mix(a>>8&0xff,b>>8&0xff,f)<<8 | mix(a&0xff,b&0xff,f); } // calculate number of steps of gradient from specified position (only values >0) public int[] calcGradient(int pos, int steps) { int[] result=new int[steps]; float imp; int first=numColors-1; int endPos=pos+steps; // find 1st colour needed, clamp start position to positive values only pos=(pos>-1) ? pos : 0; for(int i=0; ipos) { first=i-1; i=numColors; } } float currWidth=(first1) { first++; currWidth=(first