xxxxxxxxxx
197
let headCenterX;
let headCenterY;
let headWidth;
let headHeight;
let rEyeX0, lEyeX0;
let shift;
let xGrowth, yGrowth;
let xFlow, yFlow;
let eyeHue;
let hairR, hairG, hairB;
let headBrightness;
let hue;
let time;
let interval;
let outInterval;
let drawTongue;
let retractTongue;
let tongueOriginX, tongueOriginY;
let tongueCurrentX, tongueCurrentY;
let tonguePeriod;
let tongueSize;
let tongueStart, tongueEnd;
let x, y;
let circleSize;
//let s;
function setup() {
createCanvas(640, 480);
headCenterX = width / 2;
headCenterY = height / 2;
headWidth = 0.5 * width;
headHeight = 0.4 * height;
rEyeX0 = (headCenterX - headWidth / 6)
lEyeX0 = (headCenterX + headWidth / 6)
shift = 0;
xGrowth = 20;
yGrowth = 40;
xFlow = 1;
yFlow = 0.5;
eyeHue = random(360);
hairR = random(100, 200);
hairG = random(100, 200);
hairB = random(50, 100);
headBrightness = random(50, 255);
hue = 0;
time = 0;
interval = 5000;
outInterval = 500;
drawTongue = false;
retractTongue = false;
tongueOriginX = headCenterX;
tongueOriginY = headCenterY + headCenterY / 5;
tongueCurrentX = tongueOriginX;
tongueCurrentY = tongueOriginY;
tonguePeriod = 20;
tongueEnd = 24;
tongueStart = 3;
tongueSize = tongueStart;
x = 0;
y = 0;
circleSize = 20;
noCursor();
}
function draw() {
background(0);
//head
colorMode(HSB);
noStroke();
fill(25, 50, headBrightness);
ellipse(headCenterX, headCenterY, headWidth, headHeight);
//tracking eyes to mouse
//irises
fill(eyeHue, 50, 50);
shift = map(mouseX, 0, width, -headWidth / 5, headWidth / 5);
circle(rEyeX0 + shift, (headCenterY - headHeight / 6), headWidth / 7);
circle(lEyeX0 + shift, (headCenterY - headHeight / 6), headWidth / 7);
//pupils
fill(0);
circle(rEyeX0 + shift, (headCenterY - headHeight / 6), headWidth / 15);
circle(lEyeX0 + shift, (headCenterY - headHeight / 6), headWidth / 15);
//animated hair
colorMode(RGB);
strokeWeight(2);
stroke(hairR, hairG, hairB);
noFill();
let hairX = (headCenterX - headWidth / 4);
let hairY = (headCenterY - headHeight / 2 + headHeight / 10);
//left-right sway
if (xGrowth < -50) {
xFlow = 1;
} else if (xGrowth > 50) {
xFlow = -1;
}
xGrowth = xGrowth + xFlow;
//up-down bounce
if (yGrowth < 40) {
yFlow = 0.5;
} else if (yGrowth > 50) {
yFlow = -0.5;
}
yGrowth = yGrowth + yFlow;
for (let i = 1; i < 50; i++) {
curve(hairX, hairY, hairX, hairY, hairX + xGrowth, hairY - yGrowth, mouseX, mouseY);
hairX = hairX + 3;
}
//curve(259,122,259,97,358,42,mouseX,mouseY);
//bait
colorMode(RGB);
strokeWeight(0);
fill(255);
//pull it into the mouth
if (retractTongue === true) {
circle(tongueCurrentX, tongueCurrentY, circleSize);
//freeze it while tongue is drawn. To avoid bug of tongue drawing to infinity
//if mouse is moving
} else if (drawTongue === true) {
circle(targetX, targetY, circleSize);
} else {
//standby position, follows mouse
circle(mouseX, mouseY, circleSize);
}
//mouth
colorMode(RGB);
stroke(255, 0, 0);
strokeWeight(tongueStart);
line(tongueOriginX - 50, tongueOriginY, tongueOriginX + 50, tongueOriginY);
//draw tongue extraction
//condition for drawing the tongue - after set time interval
if ((millis() - time) > interval) {
//print('tongue', millis());
drawTongue = true;
targetX = mouseX;
targetY = mouseY;
time = millis();
}
//condition for starting to retract - when reaching target
if ((drawTongue === true) && (dist(tongueCurrentX, tongueCurrentY, targetX, targetY) < 1)) {
retractTongue = true;
drawTongue = false;
}
//animating the tongue towards the target
if (drawTongue === true) {
colorMode(RGB);
stroke(255, 0, 0);
strokeCap(SQUARE);
tongueCurrentX = map(x, 0, tonguePeriod, tongueOriginX, targetX);
tongueCurrentY = map(y, 0, tonguePeriod, tongueOriginY, targetY);
//targetX=mouseX;
//targetY=mouseY;
//tongueSize = map(x,0,tonguePeriod,tongueStart,tongueEnd)
x++;
y++;
strokeWeight(tongueSize);
line(tongueOriginX, tongueOriginY, tongueCurrentX, tongueCurrentY);
}
//animating the tongue retracting to the mouth
if (retractTongue === true) {
colorMode(RGB);
stroke(255, 0, 0);
strokeCap(SQUARE);
strokeWeight(tongueSize);
tongueCurrentX = map(x, 0, tonguePeriod, tongueOriginX, targetX);
tongueCurrentY = map(y, 0, tonguePeriod, tongueOriginY, targetY);
x--;
y--;
line(tongueOriginX, tongueOriginY, tongueCurrentX, tongueCurrentY);
}
//end condition
if ((retractTongue === true) && (dist(tongueOriginX, tongueOriginY, tongueCurrentX, tongueCurrentY) < 1)) {
retractTongue = false;
}
} //end of draw loop
function mousePressed() {
print(mouseX, mouseY);
}