/* Automated Cubism
this function draws faces using a number of variables to control 
the face shape and placement and scale of facial features to create
a range of possibilites Picasso could be proud of.
*/


void setup() {
size (400,400);
noLoop();
smooth();
}

void draw() {
drawPicasso //square 1
 (0,0,
 1,0,0,
 .8,70,10,
 1,0,0,
 .8,70,10,
 1,0,0,
 0);
translate(133,0); //square 2
drawPicasso
 (10,0,
 1,0,0,
 .7,85,15,
 1,0,0,
 .7,85,10,
 1,15,-1,
 0);
translate(133,0); //square 3
drawPicasso
 (15,10,
 .8,10,14,
 .8,50,10,
 1,30,0,
 1,-10,0,
 .9,30,8,
 0);
translate(0,133); //square 6
drawPicasso
 (24,24,
 .8,10,14,
 .8,50,10,
 1,0,3,
 1,15,0,
 .7,25,34,
 90);
translate(-133,0); //square 5
drawPicasso
 (24,24,
 1,0,0,
 .8,70,10,
 1,0,0,
 .8,70,10,
 .9,23,8,
 64);
translate(-133,0); //square 4
drawPicasso
 (10,20,
 1,0,0,
 .8,70,10,
 1,0,0,
 .8,70,10,
 .9,23,8,
 0);
translate(0,133); //square 7
drawPicasso
 (10,20,
 1,-10,0,
 1,25,10,
 1,-10,0,
 .8,50,20,
 1,0,0,
 45);
translate(133,0); //square 8
drawPicasso
 (25,25,
 1.2,10,0,
 1,-10,10,
 1,-10,0,
 .9,30,7,
 1,0,0,
 45);
translate(133,0); //square 9
drawPicasso
 (20,20,
 1.1,-10,0,
 .8,60,8,
 1,-10,3,
 1.25,5,-7,
 .8,0,15,
 86);
}


void drawPicasso
(float a, float b, //face: chin,nose
 float Res,float Rex,float Rey, //right eye
 float Les,float Lex,float Ley, //left eye
 float Rbs,float Rbx,float Rby, //right brow
 float Lbs,float Lbx,float Lby, //left brow
 float lips,float c,float d, //mouth
 float h) //neck
{
 frame();
noFill();
stroke(0);
strokeWeight(1.5);
 hair( );
 Rcurve( );
 face(a,b);
 Reye(Res,Rex,Rey);
 Leye(Les,Lex,Ley);
 Reyebrow(Rbs,Rbx,Rby );
 Leyebrow(Lbs,Lbx,Lby);
 mouth(lips,c,d);
 neck(h);
 RRcurve( );
}
 
void frame() {
noStroke();
  fill(237,38,75);
rect(0,0,133,133);  //square background
 fill(70,83,193);
beginShape();  //upper right corner
 vertex(133,73);
 vertex(40,0);
 vertex(133,0);
endShape();
 fill(242,242,29);
beginShape();  //hair
 vertex(76,2.8);
 bezierVertex(62.8,3.3,51.4,3.6,40.4,10);
 bezierVertex(23.3,19.3,5,47.7,16.8,80.8);
 bezierVertex(24,98.5,7,102.8,3.5,117);
 bezierVertex(2.6,121,1.5,128.3,5,133);
 vertex(50,133);
 vertex(60,91);
endShape();
fill(252,145,3);
beginShape();  //neck
 vertex(50,133);
 vertex(60,91);
 vertex(87.2,102.4);
 bezierVertex(84.5,104,85.5,128.2,88,132.8);
endShape();
 fill(49,116,79);
beginShape(); //lower right corner
 vertex(87.2,102.4);
 bezierVertex(84.5,104,85.5,128.2,88,132.8);
 vertex(133,133);
 vertex(133,73);
 vertex(125,60);
endShape();
}
  
void hair() {
  //fill(255,176,3);
 pushMatrix(); 
  for(int i=0; i<5; i++) {
    strand();
  }
 popMatrix();
 noFill();
}
 
void strand() {
 bezier(76,2.8,62.8,3.3,51.4,3.6,40.4,10);
 bezier(40.4,10,23.3,19.3,5,47.7,16.8,80.8);
 bezier(16.8,80.8,24,98.5,7,102.8,3.5,117);
 bezier(3.5,117,2.6,121,1.5,128.3,5,130.9); 
 scale(.9);
 translate(15,15);
} 

void face(float a,float b) {
fill(211,197,250);
beginShape();
vertex(78,4.3);
bezierVertex(31,7.5,18.6,83,75.7,100.6);
bezierVertex(82,102.5,94.5+a,104.7,97+a,95);
bezierVertex(98.3+a,90.5,94.3+a,88,97.3+a,83.5);
bezierVertex(99.5+a,78.6,94+a,79.5,98+a,73);
bezierVertex(100.6+a,68,92+a,60.8,99+a,60);
bezierVertex(101.7+b,60.3,106.6+b,61.6,107.8+b,58);
bezierVertex(108.8+b,53,101.5+b,36.5,101+b,28.5);
bezierVertex(101+b,23.5,97+b,4.3,78,4.3);
endShape();
noFill();
}

void Reye(float Res,float Rex,float Rey) //right eye controls
{
pushMatrix();
scale (Res);
translate (Rex,Rey);
 bezier(61.6,37.6,67.3,27.3,86.3,29,90,40.2);
 bezier(65,38.5,67,42.5,78.3,46.5,86.6,40.8);
 ellipse(76,37,9,9);
popMatrix();
}

void Leye(float Les,float Lex,float Ley) //left eye controls
{
pushMatrix();
scale (Les);
translate (Lex,Ley);
 bezier(61.6,37.6,67.3,27.3,86.3,29,90,40.2);
 bezier(65,38.5,67,42.5,78.3,46.5,86.6,40.8);
 ellipse(76,37,9,9);
popMatrix();
}

void Reyebrow(float Rbs,float Rbx,float Rby) //right eyebrow controls
{
pushMatrix();
scale (Rbs);
translate (Rbx,Rby);
 bezier(56,27,68,16.8,85,19.5,92.3,28.4);
popMatrix();
}

void Leyebrow(float Lbs,float Lbx,float Lby) //left eyebrow controls
{
pushMatrix();
scale (Lbs);
translate (Lbx,Lby);
 bezier(56,27,68,16.8,85,19.5,92.3,28.4);
popMatrix();
}

void mouth(float lips,float c,float d) {
pushMatrix();
scale(lips);
translate(c,d);
 bezier(79.5,77.3,86.5,76.8,90,73,96.4,76.5);
 bezier(96.4,76.5,101,73,104,77.5,109.4,77.4);
 bezier(82.3,77.7,90.3,80,98.8,80,107,78);
 bezier(83.3,79,91,85,99.5,85,105.3,79.6);
popMatrix();
}

void neck(float h) {
noFill();
stroke(0);
bezier(87.2,102.4-h,84.5,104-h,85.5,128.2,88,132.8);
}

void Rcurve() {
fill(255,231,5);
bezier(82.6,4,143.8,5.8,128.6,100,95.6,102);
noFill();
}

void RRcurve() {
bezier(124.5,66.5,125.7,85.3,138,110,118,133);
}
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