Project 2 – Variable Faces (Dog)

Click through for color and other variable changes

sketch

var rightearX = 360;
var rightearY = 240;
var leftearX = 120
var leftearY = 240
var pupilH = 29
var eyebrow = 211
var nose = 120
var tongue = 43
var r = 80
var g= 35
var b= 80
var red = 255
var green = 255
var blue = 255
var beardR = 213
var beardG = 227
var beardB = 244
 
function setup() {
    createCanvas(500, 500);
}
 
function draw() {
    background("white");
    noStroke();
//facebase
    fill(red,green,blue);
        rect(144,150,214,198,50);
//facehood-dark color
    fill(r,g,b);
        rect(144,150,214,162,50);
//faceeyes
    fill(red,green,blue);
        rect(176,192,66,111,33);
        rect(259,192,66,111,33);
//nose
    fill(red,green,blue);
        ellipse(249,337,nose,113);
//tongue
    fill("red");
        rect(229,311,41,tongue,20);
//beard
    fill(beardR,beardG,beardB);
        quad(195,341,216,363,263,316,242,294);
        quad(239,316,260,294,307,341,286,363);
//white eyes
    fill("white");
        ellipse(209,247,37,41);
        ellipse(293,247,37,41);
//darkest color
    fill(r,g,b);
    //ears
        triangle(299,139,383,156,rightearX,rightearY);
        triangle(200,139,116,151,leftearX,leftearY);
    //pupil
        ellipse(208,252,24,pupilH);
        ellipse(293,252,24,pupilH);
    //eyebrows
        rect(189,eyebrow,40,9,5);
        rect(274,eyebrow,40,9,5);
    //snout
        ellipse(250,304,60,34);
}
 
function mousePressed() {
    rightearX = random(350, 390);
    rightearY = random(240, 340);
    leftearX = random(110,150);
    leftearY = random(240,340);
    pupilH = random(20,38);
    eyebrow = random(200,224);
    nose = random(120,150);
    tongue = random(43,80);
    r = random (0,100);
    g = random(0,100);
    b = random (0,100);
    red = random (100,255);
    green = random (100,255);
    blue = random (100,255);
    beardR = random (200,255);
    beardG = random (200,255);
    beardB = random (200,255);
}

Project 02

Variable Face

sketchDownload
// Ilia Urgen
// Section B

//background color
var r = 128;
var g = 235;
var b = 255;

//shirt color
var r1 = 217;
var g1 = 0;
var b1 = 0;

var faceWidth = 480;
var faceHeight = 660;

var neckWidth = 250; 

var eyebrowHeight = 518;
var eyebrowThickness = 30;

var eyeDiameter = 60;

var eyeCenterX1 = 400;
var eyeCenterY1 = 575;
var eyeCenterX2 = 600;

//nose width coordinates
var noseX = 500;
var noseY = 540;

var mouth = 3;

function setup() {
    createCanvas (1000, 1000);
}                                   
                                    
function draw() {                   
    background (r, g, b);

    //neck outline
    noStroke();
    fill (243, 207, 187);
    rect (375, 500, neckWidth, 800);        
    
    //face outline                      
    ellipse (500, 600, faceWidth, faceHeight);  

    //left ear
    arc (500-(faceWidth/2)-15,620,80,160,PI + HALF_PI,PI + HALF_PI);  
    
    //right ear
    arc (500+(faceWidth/2)+15,620,80,160,PI + HALF_PI,PI + HALF_PI);  

    //left eye
    fill (0,0,0); //black
    ellipse (eyeCenterX1, eyeCenterY1, eyeDiameter + 50, eyeDiameter);  
    fill (255,255,255); //white
    ellipse (eyeCenterX1, eyeCenterY1, eyeDiameter + 30, eyeDiameter); 
    fill (102,51,0); //brown
    ellipse (eyeCenterX1, eyeCenterY1, eyeDiameter, eyeDiameter);
    fill (0,0,0); //black
    ellipse (eyeCenterX1, eyeCenterY1,12,12);
    fill (255,255,255); //white
    ellipse (eyeCenterX1, eyeCenterY1,5,5);

    //right eye
    fill (0,0,0); //black
    ellipse (eyeCenterX2, eyeCenterY1, eyeDiameter + 50, eyeDiameter);
    fill (255,255,255); //white
    ellipse (eyeCenterX2, eyeCenterY1, eyeDiameter + 30, eyeDiameter);
    fill (102,51,0); //brown
    ellipse (eyeCenterX2, eyeCenterY1, eyeDiameter, eyeDiameter);
    fill (0,0,0); //black
    ellipse (eyeCenterX2, eyeCenterY1,12,12);
    fill (255,255,255); //white
    ellipse (eyeCenterX2, eyeCenterY1,5,5);

    //nose
    fill (240,190,180);
    triangle (noseX - 50,700,500,noseY,noseX + 50,700);
    
    //t-shirt                                                              
    fill (r1,g1,b1);                                              
    quad (500-(neckWidth/2),920,200,1000,800,1000,500+(neckWidth/2),920);

    //left eyebrow
    noFill();
    strokeWeight (eyebrowThickness);
    stroke (55,39,45);
    arc (400,eyebrowHeight,120,30,PI,0);

    //right eyebrow
    arc (600,eyebrowHeight,120,30,PI,0);

    //mouth
    noFill();
    strokeWeight (35);
    stroke (193,104,115);
    
    //sad face
    if (mouth == 1) { 
        arc (500,785,180,40,PI,0);
    }

    //happy face
    else if (mouth == 2) {
        arc (500,775,180,40,0, PI);
    }

    //shocked face
    else if (mouth == 3) {
        fill (255);
        stroke (255);
        ellipse (500,790,115,10);

        noFill();
        strokeWeight (35);
        stroke (193,104,115);
        arc (500,770,180,40,PI,0);
        arc (500,780,180,40,0, PI);
    }

    //ear lines
    noFill();
    stroke (55,39,45);
    strokeWeight (2);

    arc (500-(faceWidth/2)-20,625,30,100,HALF_PI, PI + HALF_PI);
    arc (500+(faceWidth/2)+20,625,30,100,PI + HALF_PI, HALF_PI);

    //hair
    strokeWeight (eyebrowThickness);

    line (300,660-(faceHeight/2.5),100,(faceHeight/2)-20);
    line (310,660-(faceHeight/2.5),120,(faceHeight/2)-25);
    line (320,660-(faceHeight/2.5),140,(faceHeight/2)-30);

    line (330,660-(faceHeight/2.5),160,(faceHeight/2)-35);
    line (340,660-(faceHeight/2.5),180,(faceHeight/2)-40);
    line (350,660-(faceHeight/2.5),200,(faceHeight/2)-45);

    line (360,660-(faceHeight/2.5),220,(faceHeight/2)-50);
    line (370,660-(faceHeight/2.5),240,(faceHeight/2)-55);
    line (380,660-(faceHeight/2.5),260,(faceHeight/2)-60);

    line (390,660-(faceHeight/2.5),280,(faceHeight/2)-65);
    line (400,660-(faceHeight/2.5),300,(faceHeight/2)-70);
    line (410,660-(faceHeight/2.5),320,(faceHeight/2)-75);

    line (420,660-(faceHeight/2.5),340,(faceHeight/2)-80);
    line (430,660-(faceHeight/2.5),360,(faceHeight/2)-85);
    line (440,660-(faceHeight/2.5),380,(faceHeight/2)-90);

    line (450,660-(faceHeight/2.5),400,(faceHeight/2)-95);
    line (460,660-(faceHeight/2.5),420,(faceHeight/2)-100);
    line (470,660-(faceHeight/2.5),440,(faceHeight/2)-105);

    line (480,660-(faceHeight/2.5),460,(faceHeight/2)-110);
    line (490,660-(faceHeight/2.5),480,(faceHeight/2)-115);
    
    line (500,660-(faceHeight/2.5),500,(faceHeight/2)-120);
    
    line (510,660-(faceHeight/2.5),520,(faceHeight/2)-115);
    line (520,660-(faceHeight/2.5),540,(faceHeight/2)-110);

    line (530,660-(faceHeight/2.5),560,(faceHeight/2)-105);
    line (540,660-(faceHeight/2.5),580,(faceHeight/2)-100);
    line (550,660-(faceHeight/2.5),600,(faceHeight/2)-95);

    line (560,660-(faceHeight/2.5),620,(faceHeight/2)-90);
    line (570,660-(faceHeight/2.5),640,(faceHeight/2)-85);
    line (580,660-(faceHeight/2.5),660,(faceHeight/2)-80);

    line (590,660-(faceHeight/2.5),680,(faceHeight/2)-75);
    line (600,660-(faceHeight/2.5),700,(faceHeight/2)-70);
    line (610,660-(faceHeight/2.5),720,(faceHeight/2)-65);

    line (620,660-(faceHeight/2.5),740,(faceHeight/2)-60);
    line (630,660-(faceHeight/2.5),760,(faceHeight/2)-55);
    line (640,660-(faceHeight/2.5),780,(faceHeight/2)-50);

    line (650,660-(faceHeight/2.5),800,(faceHeight/2)-45);
    line (660,660-(faceHeight/2.5),820,(faceHeight/2)-40);
    line (670,660-(faceHeight/2.5),840,(faceHeight/2)-35);

    line (680,660-(faceHeight/2.5),860,(faceHeight/2)-30);
    line (690,660-(faceHeight/2.5),880,(faceHeight/2)-25);
    line (700,660-(faceHeight/2.5),900,(faceHeight/2)-20);

}

function mousePressed() {
    
    //background color
    r = random (0,255);
    g = random (0,255);
    b = random (0,255);

    //shirt color
    r1 = random (0,255);
    g1 = random (0,255);
    b1 = random (0,255);

    faceWidth = random (400, 900);
    faceHeight = random (400, 800);

    eyebrowThickness = random (10,50);
    eyebrowHeight = random (500, 545);

    eyeDiameter = random (20,80);
    eyeCenterY1 = random (570,600);

    //nose width coordinates
    noseX = random (480,520);
    noseY = random (500,590);

    //mouth option 1,2, or 3
    mouth = int(random (1,4));
}

SydneyCha-Project-02-Variable-Face

sketch
//Sydney Cha
//Section D

var eyeSize = 20;
var faceWidth = 100;
var faceHeight = 150;

var r = 207;
var g = 185;
var b = 151;

var re = 100;
var ge = 100;
var be = 100;
 
function setup() {
    createCanvas(300, 300);
}
 
function draw() {
    background(re);

    ellipse(width / 3, height / 2, faceWidth / 3, faceWidth / 3); //left ear
    ellipse(2*width / 3, height / 2, faceWidth / 3, faceWidth / 3); //right ear

    fill(r, g, b);
    ellipse(width / 2, height / 2, faceWidth,  faceHeight); //face

    var eyeLX = width / 2 - faceWidth * 0.25;
    var eyeRX = width / 2 + faceWidth * 0.25;
    fill(re, ge, be);
    ellipse(eyeLX, height / 2, 2*eyeSize/3, 2*eyeSize); //left eye
    ellipse(eyeRX, height / 2, 2*eyeSize/3, 2*eyeSize); //right eye

    fill(200, 70, 70);
    arc(width / 2, 2*height / 3, 20, 10, TWO_PI, PI); //mouth

    line(width / 2, height / 2, width / 2, faceHeight - 10); //nose
}
 
function mousePressed() {
    faceWidth = random(100, 120);
    faceHeight = random(130, 200);
    eyeSize = random(10, 30);

    r = random(160, 240);
    g = random(180, 200);
    b = random(150, 180);

    re = random(95, 255);
    ge = random(95, 255);
    be = random(95, 255);
}

Project 02: Variable Face

Variable Face
var faceWidth = 200
var faceHeight = 300
var faceColor = 255
var eyeSize = 40
var eyeL = 20
var eyeR = 20
var r = 0
var g = 0
var b = 0
var mouth = 1

function setup() {
    createCanvas(480,640);
}

function draw() {
    background(180);

    //head
    fill(r,g,b);
    ellipse(width/2,height/2,faceWidth, faceHeight);  

    //eyeballs
    fill(255);
    ellipse(eyeL,height/2,50,30);     //left
    ellipse(eyeR,height/2,50,30);     //right

    //pupil ellipse
    fill(111, 78, 55);
    ellipse(eyeL,height/2,20,20);     //left
    ellipse(eyeR,height/2,20,20);     //right

    //nose
    fill(255);
    stroke(0,0,0);
    strokeWeight(1);
    if(eyeL<=width/2-faceWidth/4 & eyeR<=width/2+faceWidth/4){
        triangle(width/2, height/2, width/2, height/2+faceHeight/5, width/2-faceWidth/4, height/2+faceHeight/8); //left
    }else if(eyeL>=width/2-faceWidth/4 & eyeR>=width/2+faceWidth/4){
        triangle(width/2, height/2, width/2, height/2+faceHeight/5, width/2+faceWidth/4, height/2+faceHeight/8); //right
    }else{
        triangle(width/2, height/2, width/2+faceWidth/8, height/2+faceHeight/5, width/2-faceWidth/8, height/2+faceHeight/5); //mid
    }

    //mouth
    if(mouth == 1){
        fill(0);
        arc(width/2,height/2+faceHeight/4,70,50,0,PI,CHORD);    //happy
        noFill();
        strokeWeight(3);
        arc(eyeL,height/2-30,70,40,PI,2*PI);
        arc(eyeR,height/2-30,70,40,PI,2*PI);
        strokeWeight(1);
    }else if(mouth == 2){
        fill(225,0,0);
        arc(width/2,height/2+faceHeight/3,70,50,PI,2*PI,CHORD); //mad
        stroke(255,0,0);
        strokeWeight(5);
        line(eyeL-25,height/2-40,eyeL+25,height/2-20);
        line(eyeR+25,height/2-40,eyeR-25,height/2-20);
        stroke(0);
        strokeWeight(1);                                        //resets stroke
    }else if(mouth==3){
        fill(0);
        ellipse(width/2,height/2+faceHeight/3,30,30);           //scared
        strokeWeight(3);
        line(eyeL-25,height/2-20,eyeL+25,height/2-40);
        line(eyeR+25,height/2-20,eyeR-25,height/2-40);
        strokeWeight(1);
    }
}

function mousePressed(){
    faceWidth = random(180,300);
    faceHeight = random(200,340);
    faceColor = random(0,255);
    eyeL = random(width/2-faceWidth/2+25,width/2-25);
    eyeR = random(width/2+25,width/2+faceWidth/2-25);
    r = random(0,255);
    g = random(0,255);
    b = random(0,255);
    mouth = int(random(1,4));
}



//don't mind the stuff down here 

    //mouth
    //line(200,290,280,290);

    //pupil with points      
    //stroke(111, 78, 55);        
    //strokeWeight(20);
    //point(190,190);             
    //point(280,190);

    //sunglasses and frame
//    stroke(255,0,0);
//    strokeWeight(3);
//    line(320,220,350,190);      
//    fill(180,240,0);
//    rect(130,200,90,50);        
//    fill(50,158,200);
//    rect(230,200,90,50); 



    //background ellipses
    //fill(255,230,0);
    //ellipse(250,200,500,600);
    //fill(196,80,71);
    //ellipse(250,200,400,500);
    //fill(147,248,234);
    //ellipse(250,200,330,430);
    //fill(135,73,146);
    //ellipse(250,200,270,370);
    //fill(0,0,0);
    //ellipse(250,200,230,330); 

Variable Face

I want to create a simple cartoon face that has many expressions. Therefore, I add many variables including the mouth, hair, eyebrow, and so on. The outcome looks good.

Variable Face

// Setting variables for coding facial actions
var eyeSizeX = 20;
var eyeSizeY = 20;
var faceWidth = 100;
var faceHeight = 150;
var mouthExpression = 1;
var noseExpression = 1;
var hairExpression = 1;
var hairSize = 0.4;
var mouthSize = 0.1;
var r = 225
var g = 175
var b = 125
var rot = 0; 
var eyeOffAry = [-1, -0.5, 0, 0.5, 1];
var eyeOffs = 0;

function setup() {
    createCanvas(480, 640);
    angleMode(DEGREES);
}

function draw() {
    background(180);
    
    //draw face
    fill(r, g, b);
    strokeWeight(0);
    ellipse(width / 2, height / 2, faceWidth,  faceHeight);
    
    //draw hair
    //hair
    if (hairExpression <= 1) {
    fill(r-100, g-100, b-100);
    arc(width / 2, height / 2, faceWidth,  faceHeight, faceWidth*hairSize-160, -faceWidth*hairSize-20, CHORD);
    } 
    //beard
    else if (hairExpression >= 1 & hairExpression <= 2) {
    stroke(r-100, g-100, b-100);
    strokeWeight(faceWidth/5);
    arc(width / 2, height / 2, faceWidth, faceHeight, faceWidth*hairSize+40, 140-faceWidth*hairSize);
    }
    //hair line
    else if (hairExpression >= 2 & hairExpression <= 3) {
    stroke(r-100, g-100, b-100);
    strokeWeight(faceWidth/5);
    arc(width / 2, height / 2, faceWidth, faceHeight, -180+faceWidth*hairSize, -faceWidth*hairSize);
    }
    //long hair
    else if (hairExpression >= 3 & hairExpression <= 4) {
    //draw long hair behind face
    rectMode(CORNER);
    fill(r-100, g-100, b-100);
    stroke(r-100, g-100, b-100);
    strokeWeight(faceWidth/6);
    rect(width/2-faceWidth/2, height/2, faceWidth, faceHeight);
    //draw face forward
    fill(r, g, b); 
    strokeWeight(0);
    ellipse(width / 2, height / 2, faceWidth,  faceHeight);
    //draw hair forward
    fill(r-100, g-100, b-100);
    arc(width / 2, height / 2, faceWidth,  faceHeight, faceWidth*hairSize-160, -faceWidth*hairSize-20, CHORD);
    noFill();
    stroke(r-100, g-100, b-100);
    strokeWeight(faceWidth/5);
    arc(width / 2, height / 2, faceWidth, faceHeight, -180, 0);
    }


    //draw eyes
    stroke(0);
    strokeWeight(0);
    var eyeLX = width / 2 - faceWidth * 0.15;
    var eyeRX = width / 2 + faceWidth * 0.15;
    fill(255);
    ellipse(eyeLX, height / 2, eyeSizeX, eyeSizeY);
    ellipse(eyeRX, height / 2, eyeSizeX, eyeSizeY);
    fill(0);
    ellipse(eyeLX + eyeOffs*(eyeSizeX / 4), height / 2, eyeSizeX / 2, eyeSizeY / 2);
    ellipse(eyeRX + eyeOffs*(eyeSizeX / 4), height / 2, eyeSizeX / 2, eyeSizeY / 2);

    //draw noses
    fill(r-100,g-100,b-100);
    if (noseExpression <= 1) {
    ellipse(width/2, height/2 + faceHeight*0.05, faceWidth/20, faceHeight/20);
    } else if(noseExpression >= 1 & noseExpression <=2) {
    rectMode(CENTER);
    rect (width/2, height/2 + faceHeight*0.08, faceWidth/20, 1.3*faceHeight/20);
    } else {
    triangle(width/2, height/2 + faceHeight*0.05, width/2-faceWidth/20, height/2 + faceHeight*0.1, width/2+faceWidth/20, height/2 + faceHeight*0.1)
    }
    
    //draw eyebrows
    var ebrowLX1 = width / 2 - faceWidth * 0.2;
    var ebrowLY1 = height / 2 - faceHeight * 0.15;
    var ebrowLX2 = width / 2 - faceWidth * 0.35;
    var ebrowLY2 = height / 2 - faceHeight * 0.15;
    var ebrowRX1 = width / 2 + faceWidth * 0.2;
    var ebrowRY1 = height / 2 - faceHeight * 0.15;
    var ebrowRX2 = width / 2 + faceWidth * 0.35;
    var ebrowRY2 = height / 2 - faceHeight * 0.15;
    noFill();
    stroke(0);
    strokeWeight(5);
    
    translate((ebrowLX1+ebrowLX1)/2, (ebrowLY1+ebrowLY2)/2);
    rotate(rot);
    line(10, 0, -10, 0);
    rotate(-rot);
    translate(-(ebrowLX1+ebrowLX1)/2, -(ebrowLY1+ebrowLY2)/2);

    translate((ebrowRX1+ebrowRX1)/2, (ebrowRY1+ebrowRY2)/2);
    rotate(-rot);
    line(10, 0, -10, 0);
    rotate(rot);
    translate(-(ebrowRX1+ebrowRX1)/2, -(ebrowRY1+ebrowRY2)/2);

    //draw mouth
    var mouthLX = width / 2 - faceWidth * 0.25;
    var mouthLY = height / 2 + faceHeight * 0.25;
    var mouthRX = width / 2 + faceWidth * 0.25;
    var mouthRY = height / 2 + faceHeight * 0.25;
    noFill();
    strokeWeight(0);
    if (mouthExpression <= 1) {
    //open happy mouth 
    fill(255);
    beginShape();
    curveVertex(mouthLX, mouthLY);
    curveVertex(mouthLX, mouthLY);
    curveVertex(0.5*(mouthLX+mouthRX)-faceWidth*0.1, mouthLY+faceHeight*0.1);
    curveVertex(0.5*(mouthLX+mouthRX)+faceWidth*0.1, mouthLY+faceHeight*0.1);
    curveVertex(mouthRX, mouthRY);
    curveVertex(0.5*(mouthLX+mouthRX)+faceWidth*0.1, mouthLY+faceHeight*mouthSize/2);
    curveVertex(0.5*(mouthLX+mouthRX)-faceWidth*0.1, mouthLY+faceHeight*mouthSize/2);
    curveVertex(mouthLX, mouthLY);
    curveVertex(mouthLX, mouthLY);
    endShape(); 
    } else if (mouthExpression >= 1 & mouthExpression <= 2) {
    //open sad mouth 
    fill(255);
    beginShape();
    curveVertex(mouthLX, mouthLY);
    curveVertex(mouthLX, mouthLY);
    curveVertex(0.5*(mouthLX+mouthRX)-faceWidth*0.1, mouthLY-faceHeight*0.1);
    curveVertex(0.5*(mouthLX+mouthRX)+faceWidth*0.1, mouthLY-faceHeight*0.1);
    curveVertex(mouthRX, mouthRY);
    curveVertex(0.5*(mouthLX+mouthRX)+faceWidth*0.1, mouthLY-faceHeight*mouthSize/2);
    curveVertex(0.5*(mouthLX+mouthRX)-faceWidth*0.1, mouthLY-faceHeight*mouthSize/2);
    curveVertex(mouthLX, mouthLY);
    curveVertex(mouthLX, mouthLY);
    endShape();
    } else if (mouthExpression >= 2 & mouthExpression <= 3){
    //closed mouth
    strokeWeight(5);
    beginShape();
    curveVertex(mouthLX, mouthLY);
    curveVertex(mouthLX, mouthLY);
    curveVertex(0.5*(mouthLX+mouthRX)-faceWidth*0.1, mouthRY-faceHeight*mouthSize);
    curveVertex(0.5*(mouthLX+mouthRX)+faceWidth*0.1, mouthLY-faceHeight*mouthSize);
    curveVertex(mouthRX, mouthRY);
    curveVertex(mouthRX, mouthRY);
    endShape();
    } else if (mouthExpression >= 3 & mouthExpression <= 4){
    //no expression
    strokeWeight(5);
    beginShape();
    curveVertex(mouthLX, mouthLY);
    curveVertex(mouthLX, mouthLY);
    curveVertex(mouthRX, mouthRY);
    curveVertex(mouthRX, mouthRY);
    endShape();
    }
}   

//Randomize the value of variables when the user clicks to generate a new random face
function mousePressed() {
    faceWidth = random(100, 200);
    faceHeight = random(150, 250);
    eyeSizeX = random(20, 30);
    eyeSizeY = random(10, 30);
    mouthExpression = random(0, 4);
    noseExpression = random(0, 3);
    hairExpression = random(0, 5);//give some chance between 4-5 for no hair
    mouthSize = random(-0.1, 0.1);
    hairSize = random(0.1, 0.2);
    eyeOffs = random(eyeOffAry);
    r = random(100, 255);
    g = random(100, 255);
    b = random(100, 255);
    rot = random(-45, 45);
}

Project-02-Variable-Face Section D

I created an alien-like girl! I enjoyed the creativity of the process and clicking my mouse to generate well-proportioned ones with a nice color pallet.

sketch- generative artDownload
// Sandy Youssef
// Section D
var eyeSizeW = 10;
var eyeSizeH = 10;
var pupilSize = 10
var faceWidth = 100;
var faceHeight = 120;
var skinR = 255
var skinG = 178
var skinB = 102


function setup() {
    createCanvas(480, 640);
}

function draw() {
    background(180);
    noStroke();
    // hair
    fill(skinR - 70, skinG - 70, skinB - 70);
    ellipse(width/2, height/2, 200, 250); 
    // bow
    fill(255);
    ellipse(width/2, height*0.30, 40, 40); 
    triangle(180, 155, 180, 230, 240, 196); 
    triangle(300, 155, 300, 230, 230, 196);
    fill(skinR - 50, skinG - 50, skinB - 50);
    // ears
    fill(255);
    ellipse(width* 0.38, height/2, 30, 40); 
    ellipse(width* 0.62, height/2, 30, 40);
    // neck
    fill(skinR - 40, skinG - 40, skinB - 40);
    rect(width* 0.45, height/2, 45, 90); 
    // face
    fill(skinR, skinG, skinB);
    ellipse(width / 2, height / 2, faceWidth,  faceHeight);  
    // shirt
    fill(255);
    ellipse(width/2, height* 0.75, 150, 150) 
    // eyes
    var eyeLX = width / 2 - faceWidth * 0.25;
    var eyeRX = width / 2 + faceWidth * 0.25;
    fill(255);
    ellipse(eyeLX, height / 2, eyeSizeW, eyeSizeH);
    fill(255);
    ellipse(eyeRX, height / 2, eyeSizeW, eyeSizeH);
    fill(0);
    var pupilL = width/2 - faceWidth * 0.25;
    var pupilR = width/2 + faceWidth * 0.25;
    fill(skinR - 50, skinG - 50, skinB - 50);
    ellipse(pupilL, height/2, pupilSize, pupilSize); // left pupil
    ellipse(pupilR, height/2, pupilSize, pupilSize); // right pupil
    // nose
    var nose1 = width/2 - faceHeight* 0.05;
    var nose2 = width/2 + faceHeight * 0.05;
    var nose3 = width/2 - faceWidth * 0.005;
    fill(skinR - 40, skinG - 40, skinB - 40);
    triangle(nose1, height*0.55, nose2, height*0.55, nose3, height*0.5)
    // mouth
    fill(238, 131, 163); 
    arc(width/2, height* 0.57, 40, 23, radians(0), radians(180));  // lips
    fill(255);
    arc(width/2, height* 0.574, 30, 15, radians(0), radians(180)); // teeth
}


function mousePressed() {
    // when the user clicks, these variables are reassigned
    // to random values within specified ranges.
    faceWidth = random(90, 180);
    faceHeight = random(130, 180);
    eyeSizeW = random(10,35);
    eyeSizeH = random (10,30);
    pupilSize = random(8, 12);
    skinR = random(70,230);
    skinG = random (70,230);
    skinB = random (70,230);
    mouth = random (1,3);
}

Second Project

here is my silly little thing $$

sketch/a>

My favorite part was randomizing colors and being surprised when the program generated nice color pallets.

//Evette LaComb
//Section D

var chin = 120;
var nose = 1;
var shirt = 150;
var hairR = 0;
var hairG = 0;
var hairB = 0;
var skinR = 0;
var skinG = 0;
var skinB = 0;
var mouthY = 130;
var mouthW = 30;
var mouthH = 5;
var eyeD = 20;

function setup() {
    createCanvas(200, 200);
}

function draw() {
    noStroke(); //apply to all bellow 
    background(195, 216, 212);

    fill(hairR -70, hairG -70, hairB -70); //HAIR COLOR  
        rect(35, 50, 130, 150); //background hair 
    fill(skinR +70, skinG -70, skinB -70); //SHIRT SHADE 
        ellipse(100, 200, shirt, 150)//shirt
    fill(skinR -70, skinG -70, skinB -70); //SKIN SHADOW
        triangle(60, 125, 140, 125, 100, 175); //neck
        ellipse(50, 93, 45, 45); //ear left
        ellipse(150, 93, 45, 45); //right ear

    fill(skinR, skinG, skinB); //FACE 
        ellipse(100, 90, 100, chin);//face
    fill(195, 216, 212); //forhead cover (hide top of head poking out of bangs)
        ellipse(100, 25, 100, 100)

    fill(hairR, hairG, hairB);
        ellipse(70, 64, 85, 55); //left hair Bang
        ellipse(130, 64, 85, 55); //right hair Bang

    fill(hairR -70, hairG -70, hairB -70); //Mouth and back hair shade 
        ellipse(100, mouthY, mouthW, mouthH); //mouth
    fill(skinR +70, skinG -70, skinB -70); //same shade as shirt 
        ellipse(100, 115, 20, 20); //nose

    fill(skinR -70, skinG -70, skinB -70); //EYE BAG 
        ellipse(75, 106, eyeD +5); //left eye
        ellipse(125, 106, eyeD +5); //right eye
    fill(195, 216, 212); //WHITES
        ellipse(75, 103, eyeD); //left eye
        ellipse(125, 103, eyeD); //right eye
    fill(hairR -120, hairG -120, hairB -120); //PUPIL
        ellipse(75, 102, eyeD -7); //left eye
        ellipse(125, 102, eyeD -7); //right eye
}

function mousePressed() {
    chin = random(120, 150);
    shirt = random(150, 200);
    hairR = random(0, 255);
    hairG = random(0, 255);
    hairB = random(0, 255);
    skinR = random(0, 255);
    skinG = random(0, 255);
    skinB = random(0, 255);
    mouthY = random(130, 145);
    mouthW = random(10, 35);
    mouthH = random(5, 10);
    eyeD = random(10, 30);
}

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));
}

Project – 02 Variable Faces

emily-variableface
//Emily Brunner, Section C
 
var eyeSize = 60;  //size of eye
var faceWidth = 300;  //face width
var faceHeight = 300;  //face height
var faceColorR = 255; //face color red space
var faceColorB = 155;  //face color blue space
var pupilSize = 5;   //pupil width and height
var mouth = 190;  //mouth width
var mouthColorR = 255; //mouth color red space
var mouthColorG = 25;  //mouth color green space
var mouthOpen = 95;  //mouth height
var nose = 20; //nose width


function setup() {
    createCanvas(640, 480);
    text("p5.js vers 0.9.0 test.", 10, 15);
}

function draw() {
    strokeWeight(0);
    background(180);

    fill(faceColorR, 150, faceColorB); //head color
    ellipse(width / 2, height / 2, faceWidth,  faceHeight); //head
    
    var eyeLX = width / 2 - faceWidth * 0.2; //left eye width
    var eyeRX = width / 2 + faceWidth * 0.2; //right eye width
    fill(255, 255, 0); //color of eyes
    ellipse(eyeLX, height / 3, eyeSize, eyeSize); //height of left eye
    ellipse(eyeRX, height / 3, eyeSize, eyeSize); //height of right eye
    
    var pupilLX = width / 2 - faceWidth * 0.2; //width of left pupil
    var pupilRX = width / 2 + faceWidth * 0.2  //width of right pupil
    fill(0, 0, 0); //color of pupils
    ellipse(pupilLX, height / 3, pupilSize, pupilSize);  //height of left pupil
    ellipse(pupilRX, height / 3, pupilSize, pupilSize);  //height of right pupil
    
    fill (mouthColorR, mouthColorG, 156); //color of mouth
    ellipse(width / 2, height / 2 + faceHeight / 4, mouth, mouthOpen); //position of mouth relative to head
    
    fill(255, 100, 97); //color of nose
    ellipse(width / 2, height / 2, nose, nose / 2) //position of nose

}

function mousePressed() {
    faceWidth = random(300, 650);
    faceHeight = random (300, 600);
    eyeSize = random(10, 30);
    mouth = random(100, 200);
    nose = random(20, 70);
    mouthOpen = random (0, 100);
    faceColorR = random (0, 255);
    faceColorB = random (0,255);
    mouthColorR = random (0, 255);
    mouthColorG = random (0, 255);
}

This project was interesting. I had a lot of fun getting the colors to change. I am struggling with how to get objects to be relative to each other in space and change relative to each other when the mouse is pressed, so there are fewer attributes/physical features than I would like. If I were to do this again, I would probably spend more time on more facial features than the changes the face has.

project 2: variable faces

I had a fun time planning out all the changing parts of these animal faces and figuring out how to use color type variables for fur tone was interesting!

Planning each variable feature
variable animal faces
// isis berymon section D

function setup() {
    createCanvas(640, 480);
    frameRate(10);
    background(245, 232, 215); //biege
}

function draw() {
}

function mousePressed() {
    background(245, 232, 215); //biege
    var face;

    //face color generator
    if(random(3) <= 1){
        face = color(145, 191, 217); //blue
    } else if(random(3) <= 2) {
        face = color(181, 145, 217); //purple
    } else {
        face = color(232, 149, 201); //pink
    }
    
     //face
    fill(face);
    noStroke();
    ellipse(width/2, height/2, 270, 250);
    //nose
    fill(30);
    ellipse(290, 270, 60, 50);
    ellipse(350, 270, 60, 50);
    fill(face);
    ellipse(287, 265, 60, 50);
    ellipse(353, 265, 60, 50);
    fill(43, 34, 40);
    triangle(320, 270, 310, 250, 330, 250);

    //ear generator
    if(random(3) <= 1){
        //cat ears
        fill(face);
        triangle(200, 190, 230, 80, 330, 200);
        triangle(350, 190, 410, 80, 440, 200);
    } else if(random(3) <=2) {
        //dog ears
        fill(face);
        ellipse(250, 150, 80, 120);
        ellipse(390, 150, 80, 120);
    } else {
        //bunny ears
        fill(face);
        ellipse(250, 150, 60, 200);
        ellipse(390, 150, 60, 200);
    }

    //neutral eyes
        fill(30);
        ellipse(260, 220, 60, 80);
        ellipse(380, 220, 60, 80);
        fill(200);
        circle(250, 210, 30);
        circle(370, 210, 30);

    //eye expression generator
    if(random(3) <= 1) {
        //happy eyes
        fill(face);
        ellipse(260, 260, 60, 30);
        ellipse(380, 260, 60, 30);
    } else if(random(3) <=2) {
        //smug eyes
        fill(face);
        rect(230, 180, 60, 30);
        rect(350, 180, 60, 30);
    }
}