Rebecca Kim – Project 02 – Variable Face

rebecca-variableface

/*
Rebecca Kim
Section C
rykim@andrew.cmu.edu
Project-O2
*/


//define variables
var eyeSize = 20;
var faceWidth = 250;
var faceHeight = 200;
var colorX = 200;
var petalY1 = 50;
var petalY2 = 30;
var wordNumber = 0;
var colorR = 255;
var colorG = 120;
var colorB = 120;
var y1 = 285;
var y2 = 295;
var smileY=320;

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

function draw() {
	//face
	strokeWeight(5);
	background(colorX,180,180);
    ellipse(width/2, height/1.9, faceWidth, faceHeight);
    noFill(0);
    stroke(255,255,colorB);
    strokeWeight(.5);
    ellipse(width/2.1, height/1.95, faceWidth, faceHeight);

	//eyes
	strokeWeight(0);
	var eyeLX = width / 2 - faceWidth * 0.25
	var eyeRX = width / 2 + faceWidth * 0.25
	fill(colorR, colorG, colorB);
	ellipse(eyeLX, height / 2, eyeSize, eyeSize);
	ellipse(eyeRX, height / 2, eyeSize, eyeSize);

	//blush
	strokeWeight(5);
	stroke(colorR,colorG,colorB);
	line(385,y1,390,y2);
	line(395,y1,400,y2);
	line(405,y1,410,y2);

	//facial expression
	noFill();
	stroke(0);
	strokeWeight(2);
	beginShape();
	curveVertex(width/2-faceWidth*.15,smileY);
	curveVertex(width/2+faceWidth*.025,310);
	curveVertex(width/2-faceWidth*.025,310);
	curveVertex(width/2+faceWidth*.15,smileY);
	endShape();


	//larger flower
	translate(200, 300);
	strokeWeight(0);
	stroke(colorR,120,120);
	for (var i = 0; i < 10; i ++) {
	ellipse(0, 10, 10, petalY1);
	rotate(PI/5);
	}

	//smaller flower
	translate(240, -40);
	strokeWeight(0);
	fill(colorX,120,120);
	for (var i = 0; i < 10; i ++) {
	ellipse(1, 5, 7, petalY2);
	rotate(PI/3);
	}


	//text
	var word = int(wordNumber);
	if (word == 1) {
		strokeWeight(.1);
		textSize(12);
		fill(160);
		text("???", 50, 50);
	} else if (word == 2){
		noStroke();
		textSize(20);
		fill(200,160,160);
		text(":-(", 50, 50);
	} else if (word == 3){
		strokeWeight(1);
		textSize(15);
		fill(255);
		text(":-/", 50, 50);
	}

 }

 function mousePressed() {
 	faceWidth = random(200, 300);
 	faceHeight = random(150, 300);
 	eyeSize = random(10,25);
 	colorX = random(180,255);
 	colorR = random(240,255);
 	colorG = random(100,150);
 	colorB = random(80,140);
 	petalY1 = random(50,80);
 	petalY2 = random(25,40);
 	word = random(0,4);
 	wordNumber = random(0,4);
 	y1 = random(275,285);
 	y2 = random(285,295);
 	smileY = random(280,350);
 }

Navigating the world of arcs and curves was new and a bit challenging, but nonetheless rewarding once I successfully embedded it into my code!

Leave a Reply