color[] colors = {
color(0, 0, 255),
color(0, 255, 255),
color(0, 255, 0),
color(255, 255, 0),
color(255, 165, 0),
color(255, 0, 0)
};
float[] cRange = {0.0, 0.2, 0.4, 0.6, 0.8, 1.0};
void setup(){
size(500, 500);
loadPixels();
float noiseX = random(100);
float noiseY = random(100);
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
pixels[y * width + x] = getColor(translateValue(noise(noiseX + x * 0.03, noiseY + y * 0.01)));
}
}
updatePixels();
noLoop();
}
color getColor(float v){
for(int i = 0; i < cRange.length - 1; i++){
if(cRange[i] <= v && v <= cRange[i + 1]){
float newV = v - cRange[i];
float r = (red(colors[i + 1]) - red(colors[i])) * (newV / (cRange[i + 1] - cRange[i])) + red(colors[i]);
float g = (green(colors[i + 1]) - green(colors[i])) * (newV / (cRange[i + 1] - cRange[i])) + green(colors[i]);
float b = (blue(colors[i + 1]) - blue(colors[i])) * (newV / (cRange[i + 1] - cRange[i])) + blue(colors[i]);
return color(r, g, b);
}
}
return color(0);
}
float translateValue(float v){
float vv = map(v, 0, 1, -0.5, 0.5);
return vv > 0 ? vv : 1.0 + vv;
}