We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm somewhat unclear how to lerpColor() between two background colors. Currently I have a program that selects a new random background color out of an array on a key release, but I'm unsure how to animate between them after scratching my head about the lerpColor documentation. Can anyone post a suggestion or example?
Thank you!
color[] colorArray = {color(0,0,0),color(255, 192, 0),color(200, 0, 0),color(126, 255, 0)};
int currentColor;
void setup(){
size(640,480);
smooth();
noStroke();
currentColor = 0;
}
void draw(){
background(colorArray[currentColor]);
}
void keyReleased(){
if(key == 's'){
println("currentColor: "+currentColor);
int newColor = currentColor;
while (newColor == currentColor)
newColor=(int) random(colorArray.length);
currentColor = newColor;
}
}
Answers
Ended up doing an alpha. This oddly works. Just leaving it here in case people stumble on it.
http://pastebin.com/7pYiCAeS
Huh. That's odd. I have no idea why that works....
Edit O-oh. Ok, I see why that works. You are slowly painting the new color on at 10/256ths transparency each frame, until it eventually becomes the only color. I could see it happening much more clearly when I dropped frameRate to ~3.
Anyway, neat solution.
An alternative: If you want a linear interpolation, and if you want it to work with
background()
, try using a timer or a countdown: "After I press 's', set a countdown, and do a lerp each draw until countdown = 0 and then stop."Please link between crossposts.
Note that this question has an answer here: http://stackoverflow.com/questions/39603472/color-change-a-background-in-processing-w-out-affecting-particles