void setup() {
size(400,400);
background(255);
colorMode(HSB, 360, 100, 100);
smooth();
noLoop();
}
void draw() {
for(int y = 1; y<4; y++) {
for(int x = 1; x<4; x++) {
face( (x * 100) - 50, (y * 100) - 50, int(random(10, 85)), int(random(3.9) ) );
}
}
}
void face(int positionx, int positiony, int shape, int features) {
fill(30, 90, 94);
stroke(30, 9, 29);
int shapeInverse = 110 - shape;
int halfShape = shape/2;
int eyeHeight = positiony + shapeInverse/3;
int reye = (positionx + halfShape) + (shape/3);
int leye = (positionx + halfShape) - (shape/3);
int mouth = positiony + ( (2 * shapeInverse) / 3 );
strokeWeight(1);
//face
rect(positionx, positiony, shape, shapeInverse);
strokeWeight(3);
//eyes
line(reye, eyeHeight, reye, (eyeHeight + 5) );
line(leye, eyeHeight, leye, (eyeHeight + 5) );
//mouth
line( (positionx + halfShape) - shape/3, mouth, (positionx + halfShape) + shape/3, mouth);
for(features = features; features>0; features--) {
int i = int( random(3.9) );
//hair
if(i == 0) {
strokeWeight(1);
fill(0, 0, 0);
bezier(positionx, positiony, positionx, (positiony - 20), (positionx + shape), (positiony - 20), (positionx + shape), positiony);
}
//mostache
else if(i == 1) {
strokeWeight(4);
stroke(0, 0, 0);
line( (((positionx + halfShape) - shape/3) - 3), (mouth - 4), ( ((positionx + halfShape) + shape/3 ) + 3), (mouth - 4) );
}
//soul patch
else if(i == 2) {
stroke(0, 0, 0);
strokeWeight(5);
line( (positionx + halfShape), (mouth + 5), (positionx + halfShape), (mouth + 9) );
}
//glasses
else if(i == 3) {
noFill();
stroke(0, 0, 0);
strokeWeight(1);
ellipse(leye, eyeHeight + 2, 15, 15);
ellipse(reye, eyeHeight + 2, 15, 15);
line(positionx, eyeHeight + 2, leye - 7.5, eyeHeight + 2);
line(positionx + shape, eyeHeight + 2, reye + 7.5, eyeHeight + 2);
bezier(leye + 7.5, eyeHeight + 2, leye + 7.5, eyeHeight - 2, reye - 7.5, eyeHeight - 2, reye - 7.5, eyeHeight + 2);
}
}
}
Exercise 05: Create a function that draws a face. Use two parameters to change the shape and features of the face. Using your function, draw 9 faces in the display window in a regular 3x3 matrix. Use different parameters for each face drawn to give each a unique shape