Hi, I’m new to Processing. I’m using the program as an introduction to coding in my high school class.
I’m currently making a face but I’m having trouble with switching the display of two shapes.
PShape face1, head, eye1, eye2, pupil1, pupil2, mouth;
PShape face2, head1, eye3, eye4, mouth1;
void setup () {
size(1200, 850);
face1 = createShape(GROUP);
head = createShape(ELLIPSE, 100, 100, 150, 150);
head.setFill(color(255, 205, 148));
eye1 = createShape(ELLIPSE, 75, 85, 30, 20);
eye1.setFill(color(255));
eye2 = createShape(ELLIPSE, 125, 85, 30, 20);
eye2.setFill(color(255));
pupil1 = createShape(ELLIPSE, 75, 85, 10, 10);
pupil1.setFill(color(0));
pupil2 = createShape(ELLIPSE, 125, 85, 10, 10);
pupil2.setFill(color(0));
mouth = createShape(ARC, 100, 125, 80, 50, 0, 3.14);
mouth.setFill(color(255, 205, 148));
face1.addChild(head);
face1.addChild(eye1);
face1.addChild(eye2);
face1.addChild(pupil1);
face1.addChild(pupil2);
face1.addChild(mouth);
face2 = createShape(GROUP);
head1 = createShape(ELLIPSE, 100, 100, 151, 151);
head1.setFill(color(255, 205, 148));
eye3 = createShape(ELLIPSE, 75, 85, 30, 20);
eye3.setFill(color(219, 164, 130));
eye4 = createShape(ELLIPSE, 125, 85, 30, 20);
eye4.setFill(color(219, 164, 130));
mouth1 = createShape(ARC, 100, 125, 80, 50, 0, 3.14);
mouth1.setFill(color(255, 205, 148));
face2.addChild(head1);
face2.addChild(eye3);
face2.addChild(eye4);
face2.addChild(mouth1);
}
void draw() {
background(204);
translate(mouseX, mouseY);
shape(face1);
}
My problem arises at the last bit of code, starting with void draw() - I’m unsure of how to place an if / else statement that will allow me to switch between displaying face1 and face2 by clicking the mouse.