project 02 – click it!

sketch
//Jaden Luscher
//jluscher@andrew.cmu.edu
//Section A

var eyeSize = 40;
var r;
var g;
var b;

function setup() {
    createCanvas(200,200);
    background(205);
    text("p5.js vers 0.9.0 test.", 10, 15);
}

function draw() {
  background(157, 102, 31); //brown "hair" is the background
  noStroke();

  //generates random color values for flashing background)
  r = random(200);
  g = random(100,200);
  b = random(100);

  if (mouseIsPressed){  //surprised face
    background(r,g,b);  //flashing background

    fill(255, 120, 100);  //blushing skin color
    ellipse(random(118,122),random(98,102),120,150); //jittering face

    fill(255);
    ellipse(100,90, eyeSize, eyeSize);  //wide eyes
    fill(120, 50, 50);
    ellipse(random(99,101),random(89,91),eyeSize/4);  //small iris

    fill(255);
    rect(random(120,122),140,6,8);
    rect(random(128,130),140,6,8);
    rect(random(136,138),140,6,8);
    rect(random(144,146),140,6,8);
    rect(random(152,154),140,6,8);  //jittering teeth

    noFill();
    stroke(115, 74, 21);
    strokeWeight(2);
    arc(100,90,eyeSize*1.5,eyeSize*2,4,5,OPEN);   //raised eyebrow
    stroke(0);
    line(120,140,160,140); //flat mouth


  } else {  //resting face
    fill(40, 110, 154);
    quad(120,0,186.666,200,200,200,200,0); //blue: 2nd background color

    fill(236, 196, 163);
    ellipse(120,100,120,150); //still face

    fill(255);
    ellipse(100,90, eyeSize, eyeSize/2);  //resting eyes
    fill(120, 50, 50);
    ellipse(constrain(mouseX,95,105),constrain(mouseY,85,95),eyeSize/2.5);
    //iris follows mouse

    fill(213, 152, 133);
    triangle(160,150,145,145,120,150);  //top lip
    triangle(160,151,145,156,120,151);  //bottom lip

    noFill();
    strokeWeight(5);
    stroke(115, 74, 21);
    ellipse(100, constrain(mouseY,90,100),eyeSize*1.75);  //large glasses lens
    ellipse(175, constrain(mouseY,75,85),eyeSize);  //small glasses lens
    strokeWeight(2);
    arc(100,90,60,40,3.7,5.8,OPEN);   //eyebrow
  }
  //the earring and nose do not change
  noStroke();
  fill(213, 152, 133);
  ellipse(55,177,10);
  ellipse(55,190,10);
  fill(40, 110, 154);
  triangle(50,170,55,120,60,170);   //earring

  strokeWeight(2);
  stroke(0);
  noFill();
  line(120,0,160,120);
  line(160,120,145,125);  //lines for nose
}

Leave a Reply