xxxxxxxxxx
124
let circleX=null;
let circleY=null;
let circleColor;
let initialAppleColor;
let targetAppleColor;
let colorTransitionAmount=0;
function setup() {
createCanvas(400,400);
aka="#F22929";
midori="#9AA63F";
pinku="#DD9795";
burann="#594540";
b="#F2F2F2";
background(b);
// define the initial and final colors using RGB
initialAppleColor = color(aka);
finalAppleColor = color(midori);
setPositionAndColor();
//noLoop();
}
function setPositionAndColor(){
circleColor=burann;
if (mouseY<230){
circleX=random(70,320);
circleY=random(150,230);
}
else if (mouseY>230){
circleX=random(160,250);
circleY=random(150,310);
}
}
function mousePressed(){
setPositionAndColor();
//redraw();
}
function draw(){
// apple color transition
colorTransitionAmount+=0.005;
if (colorTransitionAmount>1)
colorTransitionAmount=0;
let appleColor=lerpColor(initialAppleColor, finalAppleColor, colorTransitionAmount);
// redraw background
background(b);
// mouse assist
fill(240);
noStroke();
rect(10,10,160,30);
fill(0);
text(`Mouse Position: (${mouseX}, ${mouseY})`, 20, 30);
// apple
fill(appleColor);
stroke(0);
strokeWeight(1.2);
ellipse(130, 180, 150, 150);
ellipse(width-130, 180, 150, 150);
quad(196,141,190,96,215,105,204,141);
quad(72,227,328,227,232,320,168,320);
line(193,140,196,140);
line(204,140,207,140);
noStroke();
rect(120,160,100,100);
rect(150,140,100,50);
quad(70.5,225,328.5,225,231,319,168,319);
// random worm bite
if(circleX!==null && circleY!==null){
fill(circleColor);
circle(circleX,circleY,20);
}
// window
stroke(0);
strokeWeight(1);
fill(b);
ellipse(120,160,32,35);
// door
rect(202,275,26,35);
ellipse(215,275,26,26);
noStroke();
rect(203,275,24,33.5);
// worm
stroke(pinku);
strokeWeight(10);
noFill();
beginShape();
curveVertex(mouseX,mouseY+2);
curveVertex(mouseX+10,mouseY);
curveVertex(mouseX+26,mouseY);
curveVertex(mouseX+40, mouseY-20);
curveVertex(mouseX+70, mouseY-3);
curveVertex(mouseX+80,mouseY);
curveVertex(mouseX+100,mouseY);
endShape();
noStroke();
fill(0);
circle(mouseX+10,mouseY-1,3.5);
}