Hey I'm still pretty new to processing and I've created some coding for one of my uni projects. The idea is that the keypresses place the facial features on top of the blank face. I've currently got 2 problems with it.
1. When i added the blank face as a background image the facial features now only stay on screen for the instance that i press the button instead of being layered over the top. I know it has something to do with loop and redraw but I can't seem to figure it out.
2. When i have the facial features working the nose and mouth layer on top of each other making previous keypressed versions visible underneath. I was trying to get it so each time a key is pressed the previous nose/mouth is erased and replaced by the new one?
Any help would be much appreciated!!!
Code:
PImage [] features = new PImage[21];
PImage bg;
int leye;
int reye;
int mouth;
int nose;
void setup(){
bg = loadImage("mattface2.png");
//background(0);
size(1224,1162);
//frameRate(1);
features[0] = loadImage("le1.png");
features[1] = loadImage("le2.png");
features[2] = loadImage("le3.png");
features[3] = loadImage("le4.png");
features[4] = loadImage("le5.png");
features[5] = loadImage("le6.png");
features[6] = loadImage("re1.png");
features[7] = loadImage("re2.png");
features[8] = loadImage("re3.png");
features[9] = loadImage("re4.png");
features[10] = loadImage("re5.png");
features[11] = loadImage("mouth1.png");
features[12] = loadImage("mouth2.png");
features[13] = loadImage("mouth3.png");
features[14] = loadImage("mouth4.png");
features[15] = loadImage("mouth5.png");
features[16] = loadImage("nose1.png");
features[17] = loadImage("nose2.png");
features[18] = loadImage("nose3.png");
features[19] = loadImage("nose4.png");
features[20] = loadImage("nose5.png");
//noLoop();
}
void draw(){
background(bg);
leye=int(random(5));
reye=int(random(5)+6);
mouth=int(random(5)+11);
nose=int(random(5)+16);
//int rand = 0;
}
void keyPressed(){
if (key == 'l' || key == 'L') {
image(features[leye],0,0, 1224,1162);
}
else if (key == 'r' || key == 'R') {
image(features[reye],0,0,1224,1162);
}
else if (key == 'm' || key == 'M') {
image(features[mouth],0,0,1224,1162);
}
else if (key == 'n' || key == 'N') {
image(features[nose],0,0,1224,1162);
}
else if (key == 's' || key == 'S') {
saveFrame("face-####.tif");
}
}