Project2 – Variable Faces

Pikachu is too cute so I make him uglier.

pikachu
/*
 * Fangzheng Zhu
 * fangzhez@andrew.cmu.edu
 * Section D
 *
 * This program draws variable faces.
 */

var eyeSize = 40;
var faceWidth = 100;
var faceHeight = 150;
var cheekSize = 40;
var TopHeadWidth = 210;
var TopHeadHeight = 180;
var BottomHeadWidth = 230;
var BottomHeadHeight = 170;
var x=40;
var y=10;
var r=35;
var z=20;
var ballSize=40;
var a=100;
var b=100;

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

function draw() {
    background(180);
    //Ball
    stroke(0);
    strokeWeight(4);
    fill(255,0,0);
    arc(a,b,ballSize,ballSize,180,360);
    fill(255,255,255);
    arc(a,b,ballSize,ballSize,0,180);
    line(a-ballSize/2,b,a+ballSize/2,b);
    ellipse(a,b,ballSize/4,ballSize/4);

    //TopFace
    noStroke();
    fill(255, 218, 36);
    ellipse(width / 2, height / 2, TopHeadWidth, TopHeadHeight);
    //BottomFace
    ellipse(width / 2, height / 2 + 50, BottomHeadWidth, BottomHeadHeight);

    //Eye black
    fill(0);
    noStroke();
    ellipse(width/2 - 45, height/2 - 10, eyeSize, eyeSize);
    ellipse(width/2 + 45, height/2 - 10, eyeSize, eyeSize);

    //Eye white
    fill(255);
    noStroke();
    ellipse(width/2 - x, height/2 -y, eyeSize - 20, eyeSize - 20);
    ellipse(width/2 + x, height/2 -y, eyeSize - 20, eyeSize - 20);

    //Nose
    fill(0);
    ellipse(width / 2, height / 2 + 20, 10, 5);

    //LeftCheek
    fill(255, 0 , 0);
    noStroke();
    ellipse(width / 2 - BottomHeadWidth/3, height / 2 + 50, cheekSize, cheekSize +10);
    //RightCheek
    ellipse(width / 2 + BottomHeadWidth/3, height / 2 + 50, cheekSize, cheekSize +10);



    //right mouth
    strokeWeight(3);
    stroke(0,0,0);
    fill(255, 218, 36);
    arc(width/2+ 17, height/2 + 30, 45, 45, z, 140);
    arc(width/2- 17, height/2 + 30, 45, 45, 40, 180-z);

    //Left Ear
    fill(255, 218, 36);
    noStroke();
    translate(width/2, height/2);
    rotate(-r);
    ellipse(-30, -150, 50, 150);
    //Right Ear
    rotate(2*r);
    ellipse(30, -150, 50, 150);
}

function mousePressed() {
    eyeSize = random(30, 50);
    BottomHeadWidth = random(210,240);
    BottomHeadHeight = random(150,180);
    TopHeadHeight = random(170, 190);
    TopHeadWidth = random(180,200);
    cheekSize = random(30, 60);
    x = random(30,40);
    y = random (8,12);
    r = random (30,45);
    z = random (10,45);
    ballSize = random (40,100);
    a = random (0,width);
    b = random (0, height);
}

Leave a Reply