xxxxxxxxxx
84
function setup() {
createCanvas(1000 , 1000);
}
function draw() {
background('white');
//FACE BG
fill('yellow');
stroke('black');
var stay = min(windowWidth, windowHeight);
strokeWeight(stay / 150);
circle(stay/2, stay/2, stay/1.6);
var leftEyeX = stay/2.91
var rightEyeX = stay / 1.63
var eyeY = stay/2.0
var eyeWidth = stay/5.34
var eyeHeight = stay/4.0
var pupilWidth = stay/16.0
// Draw the left eye
drawEye(leftEyeX , eyeY , eyeWidth, eyeHeight, stay);
// Draw the right eye
drawEye(rightEyeX, eyeY , eyeWidth, eyeHeight, stay);
//MOUTH
fill('#a6152f');
stroke(0);
strokeWeight(stay / 150);
arc(stay / 2.05, stay / 1.78, stay / 2.29, stay / 2.46, radians(0), radians(180));
line(stay / 4, stay / 1.78, stay / 1.42, stay / 1.78);
strokeWeight(stay / 150);
fill('#fb99af');
arc(stay / 1.78, stay / 1.34, stay / 4, stay / 5.34, radians(175), radians(333));
bezier(stay / 2.29, stay / 1.32, stay / 2, stay / 1.29, stay / 1.63, stay / 1.32, stay / 1.52, stay / 1.45);
fill('black');
// Calculate the position of the left pupil based on the mouse
var pupilArcHalfW = (eyeWidth-pupilWidth)/2
var pupilArcHalfH = (eyeHeight-pupilWidth)/2
var xDiff = leftEyeX - mouseX
var yDiff = eyeY - mouseY
var thet = -atan2(xDiff,yDiff)-PI/2
if (pow(mouseX - leftEyeX,2)/pow(pupilArcHalfW,2) + pow(mouseY - eyeY,2)/pow(pupilArcHalfH,2) > 1){
leftPupilX = leftEyeX+pupilArcHalfW*cos(thet)
leftPupilY = eyeY+pupilArcHalfH*sin(thet)
}else{
leftPupilX = mouseX
leftPupilY = mouseY
}
leftPupilY = min(leftPupilY,eyeY-pupilWidth/2)
// Draw the left pupil
circle(leftPupilX, leftPupilY, stay / 16);
// Calculate the position of the right pupil based on the mouse
xDiff = rightEyeX - mouseX
thet = -atan2(xDiff,yDiff)-PI/2
if (pow(mouseX - rightEyeX,2)/pow(pupilArcHalfW,2) + pow(mouseY - eyeY,2)/pow(pupilArcHalfH,2) > 1){
rightPupilX = rightEyeX+pupilArcHalfW*cos(thet)
rightPupilY = eyeY+pupilArcHalfH*sin(thet)
}else{
rightPupilX = mouseX
rightPupilY = mouseY
}
rightPupilY = min(rightPupilY,eyeY-pupilWidth/2)
// Draw the right pupil
circle(rightPupilX, rightPupilY, pupilWidth);
}
// Helper function to draw an eye
function drawEye(x, y, w, h,stay) {
fill('white');
strokeWeight(stay / 150);
arc(x, y, w, h, radians(180), radians(0));
line(x - w / 2, y, x + w / 2, y);
//console.log('x =' + mouseX);
//console.log('y =' + mouseY);
}