Project-02-Variable-Face

The hardest part of my project was attempting to debug the randomizer function.

sketch
// Zoe Lin (ID: youlin)
// Section B

var eyeSize = 20;
var faceWidth = 100;
var faceHeight = 150;
var faceType;
var noseType = 3;
var mouthType = 1;
var earType;
var pupilSize;
var browType;
var stuffType;
var r;
var g;
var b;
 
function setup() {
    createCanvas(300, 300);
    rectMode(CENTER);
}
 
function draw() {
    background(r, g, b);
    face();
    nose();
    eyes();
    //brows();
    pupils();
    mouth();
    //ears();
    //stuffs();
  
}
 
 //face shape   
function face() {
    if (faceType < 0.7) {
      ellipse(width / 2, height / 2, faceWidth,  faceHeight);
    } else {
      rect(width / 2, height / 2, faceWidth, faceHeight/1.05, 30)
    }
  
}

//eye shape
function eyes() {
    var eyeLX = width / 2 - faceWidth * 0.25;
    var eyeRX = width / 2 + faceWidth * 0.25;
    ellipse(eyeLX, height / 2, eyeSize, eyeSize);
    ellipse(eyeRX, height / 2, eyeSize, eyeSize);
}
  
//pupil size
function pupils() {
    push();
    //strokeWeight(9);
    //pupilSize = strokeWeight(1);
    if (pupilSize >= 1 & pupilSize <= 2) {
      strokeWeight(4);
    } else if (pupilSize >= 2 & pupilSize <= 3) {
      strokeWeight(5);
    } else if (pupilSize >= 3 & pupilSize <= 4) {
      strokeWeight(6);
    } else if (pupilSize >= 4 & pupilSize <= 5) {
      strokeWeight(7);
    } else if (pupilSize >= 5 & pupilSize <= 6) {
      strokeWeight(8);
    } else if (pupilSize >= 6 & pupilSize <= 7) {
      strokeWeight(9);
    } else if (pupilSize >= 7 & pupilSize <= 8) {
      strokeWeight(10);
    } else {
      strokeWeight(11);
    }
    var eyeLX = width / 2 - faceWidth * 0.25;
    var eyeRX = width / 2 + faceWidth * 0.25;
    point(eyeLX, height / 2, eyeSize);
    point(eyeRX, height / 2, eyeSize);
    //strokeWeight(random(1, 7));
    pop();
}

//nose shape
function nose() {
    var noseW = width / 2 - faceWidth * 0.04
    var noseH = height / 2 + faceHeight * 0.07
    //noseType = random(1, 5);
    if (noseType >= 1 & noseType <= 2) {
      rect(noseW+4, noseH, 7, 18, 10);
    } else if (noseType >= 2 & noseType <= 3) {
      arc(noseW+4, noseH, 10, 10, PI + TWO_PI, TWO_PI);
    } else if (noseType >= 3 & noseType <= 4) {
      push();
      strokeWeight(4);
      point(noseW+2, noseH+5);
      point(noseW+10, noseH+5);
      pop();
      //triangle(noseW-3, noseH, noseW, noseH-4, noseW+3, noseH)
    } else if (noseType >= 4 & noseType <= 5) {
     ellipse(noseW+4, noseH+3, 10, 10);
    } else if (noseType >= 5 & noseType <= 6) {
      triangle(noseW+2, noseH, noseW+5, noseH-4, noseW+8, noseH)
    }
}
  
//mouth shape
function mouth() {
    var mouthW = width / 2
    var mouthH = height / 2 + faceHeight * 0.1
    if (mouthType >= 1 && mouthType <= 2) {
      push();
      fill(0);
      ellipse(mouthW, mouthH+20, 10, 10);
      pop();
    } else if (mouthType >= 2 & mouthType <= 3) {
      push();
      noFill();
      arc(mouthW, mouthH+25, 25, 18, PI + TWO_PI, TWO_PI);
      pop();
    } else if (mouthType >= 3 & mouthType <= 4) {
      push();
      noFill();
      arc(mouthW, mouthH+2, 60, 40, PI*0.1, PI*0.9, OPEN);
      pop();
    } else if (mouthType >= 4 & mouthType <= 5) {
      line(mouthW-15, mouthH+20, mouthW+15, mouthH+20);
    }
}
 
function mousePressed() {
    faceWidth = random(100, 170);
    faceHeight = random(100, 165);
    eyeSize = random(10, 30);
    pupilSize = random(1, 9);
    faceType = random(0, 2);
    noseType = random(1, 6);
    mouthType = random(1, 5);
    r = random(20, 230);
    g = random(120, 200);
    b = random(50, 255);
    strokeWeight(random(1.5, 3));
}

Leave a Reply