hello
i’m having some trouble to smoothly change a color from a triggered event, initially mousePressed, then i will move to a timer.
I’m loading a .svg file, adding each child in a separate custom object stored in an ArrayList, assigning different colors for each shape when instantiating the objects. that’s going allright. i’m also ok with changing the color on a mousePressed event;
now i want to smoothly change the color, through event triggered lerpcolor() . i have found some examples in the old forums but they weren’t object oriented, so i’m kinda stuck to make it run as an object method.
any help appreciated.
base code
ArrayList<Mascara> masks=new ArrayList<Mascara>();
PShape s;
void settings() {
size(935, 1038);
}
void setup() {
s=loadShape("WARHOL.svg");
int count=s.getChildCount();
for (int i=0; i<count; i++) {
PShape temp=s.getChild(i);
masks.add(new Mascara(temp, i));
}
}
void draw() {
for (Mascara m : masks) {
m.display();
if (frameCount%300==0) {
m.changeColor();
println("change color");
}
}
}
void mousePressed() {
for (Mascara m : masks) {
m.sortColor();
}
}
the Mascara class
class Mascara {
PShape s;
int id;
color[] palette={#ff0000, #ff7f00, #ffff00, #00ff00, #00cfff, #005cff, #7c00ff, #ff00b1, #ffffff, #000000};
color from;
color target;
color current;
float lerpValue=0;
float lerpStep=.01;
Mascara(PShape _s, int _id) {
s=_s;
id=_id;
//current=sortColor();
sortColor();
//changeColor();
}
void sortColor() {
if (id<5) {
current=palette[floor(random(palette.length))];
} else {
current=palette[8];
}
}
/*
color sortColor() {
if (id<5) {
//current=palette[floor(random(palette.length))];
return palette[floor(random(palette.length))];
} else {
//current=palette[8];
return palette[8];
}
}
color changeColor() {
if (lerpValue<1) {
from=current;
target=sortColor();
lerpValue+=lerpStep;
return lerpColor(from, target, lerpValue);
} else {
lerpValue=0.0;
return lerpColor(from, target, lerpValue);
}
}
*/
void display() {
s.setFill(current);
shape(s, 0, 0);
}
}