Project 2 – Variable Faces

var c = 0.1;
var x;
var y;
var r = 100;

function setup() {
    createCanvas(420, 400);
    background(220);
}

function draw() {

  x = width / 2;
  y = height / 2;

  //filled head
  noStroke();
  fill(255,226,226);
  ellipse(x+20,y-20,2*r);

  //hair
  stroke(100);
  strokeWeight(35);
  line(((x-r/3)+5),(y-r-5),((x+2*r/3)+5), (y-r-5));
  stroke(40);
  line((x-r/3),(y-r),(x+2*r/3),(y-r));

  //outline head
  noFill();
  strokeWeight(10);
  stroke(230, 168,168);
  ellipse(x, y, 2*r);

  //earrings
  fill(182);
  noStroke();
  ellipse(x-(r+10),y-40,15);
  ellipse(x-(r+6),y+10,15);

  stroke(230, 168,168);
  strokeWeight(6);
  noFill();
  arc(x-(r/2),y-(r/2), 15,15,0, PI);
  arc(x+(r/3),y-(r/2), 15,15,0, PI);
  arc(x-r/6,y+(r/3), 30,15,PI/6, PI-PI/6);

  noLoop()
}

function mousePressed(){
    c = random(7);
    print(c.toString())

    if (c < 1) {
        background(220);
        //filled head
        noStroke();
        fill(255,226,226);
        ellipse(x+20,y-20,2*r);
        print("face1")

        //hair
        stroke(100);
        strokeWeight(35);
        line(((x-r/3)+5),(y-r-5),((x+2*r/3)+5), (y-r-5));
        stroke(40);
        line((x-r/3),(y-r),(x+2*r/3),(y-r));

        //outline head
        noFill();
        strokeWeight(10);
        stroke(230, 168,168);
        ellipse(x, y, 2*r);

        //earrings
        fill(182);
        noStroke();
        ellipse(x-(r+10),y-40,15);
        ellipse(x-(r+6),y+10,15);

        //face
        stroke(230, 168,168);
        strokeWeight(6);
        noFill();
        ellipse(x-(r/2),y-(r/2), 15, 15);
        ellipse(x+(r/3),y-(r/2), 15, 15);
        ellipse(x-r/6,y+(r/3), 30, 30);
    }
  else if (c > 1 & c < 2) {
      background(220);
      //filled head
      noStroke();
      fill(255,226,226);
      ellipse(x+20,y-20,2*r);

      //hair
      stroke(100);
      strokeWeight(35);
      line(((x-r/3)+5),(y-r-5),((x+2*r/3)+5), (y-r-5));
      stroke(40);
      line((x-r/3),(y-r),(x+2*r/3),(y-r));

      //outline head
      noFill();
      strokeWeight(10);
      stroke(230, 168,168);
      ellipse(x, y, 2*r);

      //earrings
      fill(182);
      noStroke();
      ellipse(x-(r+10),y-40,15);
      ellipse(x-(r+6),y+10,15);

      print("face2")
      stroke(230, 168,168);
      strokeWeight(6);
      noFill();
      ellipse(x-(r/2),y-(r/2), 15, 15);
      ellipse(x+(r/3),y-(r/2), 15, 15);
      arc(x-r/6,y+(r/3), 30,15, PI+PI/6, 0-PI/6);
      stroke(40);
      strokeWeight(12);
      line(x-(r/2),y-(r/2)-15/2-15, x-(r/2)+15/2+10, y-(r/2)-10);
      line(x+(r/3),y-(r/2)-15/2-15, x+(r/3)-15/2-10,y-(r/2)-10);
  }
  else if(c > 2 & c < 3){
      background(220);

      //filled head
      noStroke();
      fill(255,226,226);
      ellipse(x-20,y-20,2*r);

      //hair
      stroke(100);
      strokeWeight(35);
      line(((x-r/3)+5)-80,(y-r-5)+40,((x+2*r/3)+5)-80, (y-r-5)-20);
      stroke(40);
      line((x-r/3)-80,(y-r)+40,(x+2*r/3)-80,(y-r)-20);

      //outline head
      noFill();
      strokeWeight(10);
      stroke(230, 168,168);
      ellipse(x, y, 2*r);

      //earrings
      fill(182);
      noStroke();
      ellipse(x-(r+10),y-40,15);
      ellipse(x-(r+6),y+10,15);

      print("face3")
      stroke(230, 168,168);
      strokeWeight(6);
      noFill();
      arc(x-(r/2),y-(r/2), 15,15,0, PI);
      arc(x+(r/3),y-(r/2), 15,15,0, PI);
      line(x-r/6, y+(r/3), (x-r/6)+20, y+(r/3));
  }
  else if (c > 3 & c < 4) {
      background(220);
      //filled head
      noStroke();
      fill(255,226,226);
      ellipse(x-20,y+20,2*r);

      //hair
      stroke(100);
      strokeWeight(35);
      line(((x-r/3)+5)-80,(y-r-5)+40,((x+2*r/3)+5)-80, (y-r-5)-20);
      stroke(40);
      line((x-r/3)-80,(y-r)+40,(x+2*r/3)-80,(y-r)-20);

      //outline head
      noFill();
      strokeWeight(10);
      stroke(230, 168,168);
      ellipse(x, y, 2*r);

      //earrings
      fill(182);
      noStroke();
      ellipse(x-(r+10),y-40,15);
      ellipse(x-(r+6),y+10,15);

      print("face4")
      stroke(230, 168,168);
      strokeWeight(6);
      noFill();
      ellipse(x-(r/2),y-(r/2), 15, 15);
      ellipse(x+(r/3),y-(r/2), 15, 15);
      arc(x-r/6,y+(r/3), 30,15, PI+PI/6, 0-PI/6);
      stroke(40);
      strokeWeight(12);
  }
  else if(c > 4 & c < 5){
      background(220);

      //filled head
      noStroke();
      fill(255,226,226);
      ellipse(x-20,y-20,2*r);

      //hair
      stroke(100);
      strokeWeight(35);
      line(((x-r/3)+5)-80,(y-r-5)+40,((x+2*r/3)+5)-80, (y-r-5)-20);
      stroke(40);
      line((x-r/3)-80,(y-r)+40,(x+2*r/3)-80,(y-r)-20);

      //outline head
      noFill();
      strokeWeight(10);
      stroke(230, 168,168);
      ellipse(x, y, 2*r);

      //earrings
      fill(182);
      noStroke();
      ellipse(x-(r+10),y-40,15);
      ellipse(x-(r+6),y+10,15);

      print("face5")
      stroke(230, 168,168);
      strokeWeight(6);
      noFill();
      arc(x-(r/2),y-(r/2), 15,15,0, PI);
      arc(x+(r/3),y-(r/2), 15,15,0, PI);
  }
  else if(c > 5 & c < 6){
      background(220);

      //filled head
      noStroke();
      fill(255,226,226);
      ellipse(x+20,y+20,2*r);

      //hair
      stroke(100);
      strokeWeight(35);
      line(((x-r/3)+5),(y-r-5),((x+2*r/3)+5), (y-r-5));
      stroke(40);
      line((x-r/3),(y-r),(x+2*r/3),(y-r));

      //outline head
      noFill();
      strokeWeight(10);
      stroke(230, 168,168);
      ellipse(x, y, 2*r);

      //earrings
      fill(182);
      noStroke();
      ellipse(x-(r+10),y-40,15);
      ellipse(x-(r+6),y+10,15);

      print("face6")
      stroke(230, 168,168);
      strokeWeight(6);
      noFill();
      ellipse(x-(r/2),y-(r/2), 15, 15);
      ellipse(x+(r/3),y-(r/2), 15, 15);
      arc(x+(r/3),y+(r/2), 30,30,0, PI);
      line(x-(r/3),y+(r/2),x+(r/3)+15,y+(r/2));
  }
  else{
      background(220);
      //filled head
      noStroke();
      fill(255,226,226);
      ellipse(x+20,y-20,2*r);

      //hair
      stroke(100);
      strokeWeight(35);
      line(((x-r/3)+5)+20,(y-r-5),((x+2*r/3)+5)+20, (y-r-5)+20);
      stroke(40);
      line((x-r/3)+20,(y-r),(x+2*r/3)+20,(y-r)+20);

      //outline head
      noFill();
      strokeWeight(10);
      stroke(230, 168,168);
      ellipse(x, y, 2*r);

      //earrings
      fill(182);
      noStroke();
      ellipse(x-(r+10),y-40,15);
      ellipse(x-(r+6),y+10,15);

      print("face7")
      stroke(230, 168,168);
      strokeWeight(6);
      noFill();
      arc(x-(r/2),y-(r/2), 15,15,0, PI);
      arc(x+(r/3),y-(r/2), 15,15,0, PI);
      arc(x-r/6,y+(r/3), 30,15,PI/6, PI-PI/6);
  }
}

Leave a Reply