Project-02 Variable Faces

I was going to try with different expressions, but my if-else statement doesn’t seem to work for random(). However, I used mouseY instead for the crying effect.

sketchDownload
/* Jiayi Chen
   jiayiche    Section A */
function setup() {
    createCanvas(480, 640);
}

var width = 480;
var height = 640;
var x=width /100;
var y=height/100;
var faceWidth= 80*x;
var faceHeight= 80*y;
var r = 0;
var g = 0;
var b = 0;
var eyebrowshape=1;
var eyebrowy2= 27*y;
var eyebrowy1= 27*y;
var mouthSizeX = 20*x;
var mouthSizeY = 10*y;


function draw() {
    background(220);
    fill(255,229,204);
    ellipse(50*x, 50*y, faceWidth,  faceHeight); //head

    var leftEyex=50*x-faceWidth/4;                 //eyes
    var rightEyex=50*x+faceWidth/4;
    var leftEyey=50*y-faceHeight/8;
    var rightEyey=50*y-faceHeight/8;
    var eyeSizex=20*x;
    var eyeSizey=20*y;
    fill(255);
    ellipse(leftEyex, leftEyey, eyeSizex,eyeSizey);//Left eyes
    fill(r,g,b);
    ellipse(leftEyex, leftEyey, eyeSizex*2/3,eyeSizey*2/3);
    fill(255);
    ellipse(rightEyex,rightEyey,eyeSizex,eyeSizey);//Right eyes
    fill(r,g,b);
    ellipse(rightEyex,rightEyey,eyeSizex*2/3,eyeSizey*2/3);
    fill(r,g,b);                                     //hairs
    strokeWeight(0)
    rect(20*x,5*y,60*x,10*y);
    rect(20*x,15*y,10*x,7*y);
    rect(70*x,15*y,10*x,7*y);
    rect(30*x,15*y,10*x,5*y);
    rect(60*x,15*y,10*x,5*y);
    rect(40*x,15*y,15*x,2*y);
    rect(50*x,15*y,15*x,2*y);
    strokeWeight(10);                                  //eyebrow
    stroke(0);
    var z=5*x;
    var Leyebrowx1= 50*x-faceWidth/4-z ;
    var Reyebrowx1= 50*x+faceWidth/4-z;
    var Leyebrowx2= 50*x-faceWidth/4+10*x-z;
    var Reyebrowx2= 50*x+faceWidth/4+10*x-z;

    line(Leyebrowx1,eyebrowy1,Leyebrowx2,eyebrowy2); //left eyebrow
    line(Reyebrowx1,eyebrowy2,Reyebrowx2,eyebrowy1); //right eyebrow
    var mouthStroke = 2
    strokeWeight(mouthStroke);                       //mouthes
    fill(255,0,0);
    ellipse(50*x,70*y,mouthSizeX,mouthSizeY);     
    if(mouseY<=100*y/2) {        //tears
      fill(0,0,255)
      strokeWeight(0)
      rect(leftEyex,leftEyey+10*y,5*x,20*y)
      rect(rightEyex,rightEyey+10*y,5*x,20*y)
      rect(leftEyex-5*x,leftEyey+20*y,5*x,20*y)
      rect(rightEyex-5*x,rightEyey+20*y,5*x,20*y)
    }
    fill(204,102,0)
    ellipse(50*x,50*y,10*x,10*y);   

}


function mousePressed() {
    r = random(0,255);
    g = random(0,255);
    b = random(0,255);
    mouthSizeX =random(10*x,30*x);
    mouthSizeY =random(0*y,20*y);
    eyebrowy2= random (20*y,35*y)
    eyebrowy1= random (20*y,35*y)
}

Leave a Reply