xxxxxxxxxx
38
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
stroke(0);
if (mouseIsPressed) { //Change strokeWeight when mouse is pressed
strokeWeight(15);
} else {
strokeWeight(5);
}
//Head
fill(map(mouseX, 0, 400, 0, 255), 200, 200); // Fill of head react to mouseX position
rect(50, 50, 300, 300);
//Eyes
if (keyIsPressed) { //Change fill color when any key is pressed
fill(255, 0, 255);
} else {
fill(255);
}
ellipse(150, 150, sin(frameCount / 60.0) * 30 + 40); //Left Eye size controlled by sine function
ellipse(250, 150, cos(frameCount / 60.0) * 30 + 40); //Right Eye controlled by cosine function
//Nose
stroke(255, 0, 0);
if (keyIsPressed) { //Make the nose line wiggle if any key is pressed
line(200, 200, 200 + random(-10, 10), 250 + random(-10, 10)); //Nose position with randomness
} else {
line(200, 200, 200, 250);
}
//Mouse
line(100, 250 + mouseY / 10, 300, 250 + mouseY / 10); //Mouth y-positions controlled by mouseY position
}