xxxxxxxxxx
306
//define global variables to be passed into functions
let snowY = 0;
let snowX = 50;
let rainY = 0;
let rainX = 50;
let backgroundFx = 'sun';
function setup() {
createCanvas(400, 600);
}
function draw() {
background(255,251,121);
noStroke();
pressedBackground();
drawArm();
drawFace();
angleMode(DEGREES);
}
//arm behind body
function drawArm(){
//left arm hidden behind body
push();
rotate(35);
translate(110,15);
fill(131,131,131);
ellipse(100,100,30,80);
pop();
}
function drawFace(){
//face
push();
fill (212,210,210);
rect(145,50,110,130,4);
pop();
//antenna
push();
strokeWeight(1);
stroke(51);
line(200,30,200,50);
pop();
//red dot on antenna
push();
fill(255,0,0);
ellipse(200,30,25);
pop();
//mouth
rect(150,130,100,40);
//teeth
for (teeth =0; teeth <3; teeth++){
//line(x1, y1, x2, y2)
stroke('GRAY');
line (170+teeth*30,130,170+teeth*30,170);
}
//nose part of glasses
line(193,100,210,100);
//call next function
drawEye(170,95,45);
drawEye(230,95,45);
}
function drawEye(eyeX,eyeY,eyeW){
//glasses
push();
strokeWeight(1);
ellipse(eyeX,eyeY,eyeW);
pop();
//ellipse(170,95,45);
//eyeball
push();
fill(0);
if (eyeX<200){
ellipse(eyeX+5, eyeY+5, eyeW-25); //ellipse(175,100,20);
}else{
ellipse(eyeX-5, eyeY+5, eyeW-25);
}
pop();
//eye shine
push();
if (eyeX <200){
ellipse(eyeX+8, eyeY+5, eyeW-35); //ellipse(178,100,10);
}else{
ellipse(eyeX-8, eyeY+5, eyeW-35);
}
pop();
//cheeks
push();
noStroke();
fill(255, 130, 126);
if (eyeX <200){
ellipse((round(eyeX*0.9411)),round(eyeY*1.242),20); //ellipse(160,118,20);
} else {
ellipse((round(eyeX*1.05)),round(eyeY*1.242),20);
//left cheeks
}
pop();
//eyebrows triangle(x1, y1, x2, y2, x3, y3)
push();
if (eyeX <200){
fill(0);
triangle(148,68,185,68,168,59);
} else {
//right eyebrow
fill(0);
triangle(216,68,253,68,233,59);
}
pop();
//call drawBody function
drawBody(100,180,288,180,285,385,160,385,200,203);
}
function drawBody(qX1,qY1,qX2,qY2, qX3,qY3,qX4,qY4,bowCenterX,bowCenterY){
//quad(x1, y1, x2, y2, x3, y3, x4, y4, [detailX], [detailY])
//body
push();
fill(131,131,131);
quad(qX1,qY1,qX2,qY2,qX3,qY3,qX4,qY4);
//fin
arc(bowCenterX+80,280,100, 90, 180 + 45, 0,CHORD);
pop();
//tummy
push();
fill(161,161,161);
quad(qX1,qY1,qX2-70,qY2,qX3-40,qY3-50,qX4-17,qY4-60);
pop();
// quad(100,180,288-70,180,285-40,385-50,160-17,385-60);
//bow
// triangle(bowCenterX,bowCenterY,169,188,171,220);
//left triangle
push()
noStroke();
fill(39,98,201);
triangle(bowCenterX,bowCenterY,bowCenterX-31,bowCenterY-15,bowCenterX-29,bowCenterY+17);
//right triangle
triangle(bowCenterX,bowCenterY,bowCenterX+31,bowCenterY-15,bowCenterX+29,bowCenterY+17);
pop();
//middle of bow
push();
noStroke();
fill(3,133,255);
ellipse(bowCenterX,bowCenterY,20,25)
pop();
//execute drawArm
drawHand(30,80);
}
function drawHand(handWidth, handHeight){
//left hand
push();
translate(320,40)
rotate(90)
fill(131,131,131);
ellipse (200,200,handWidth,handHeight);
pop();
//right hand and arm
push();
translate(20,80)
rotate(20);
fill(131,131,131);
ellipse(250,100,handHeight,handWidth);
pop();
//call draw bottom function
drawBottom(220,465,200,180);
}
function drawBottom(bottomX,bottomY,bottomW,bottomH){
push();
noStroke();
fill(255);
arc(bottomX, bottomY, bottomW, bottomH, 300,240, OPEN);
arc(bottomX,bottomY+11, bottomW, bottomH,120,60, OPEN);
pop();
push();
fill(0);
circle(221,415,20)
pop();
//call shadow function
drawShadow();
}
function drawShadow(){
push();
noStroke();
fill(181,176,50);
quad(171,554,268,554,343,600,194,600);
pop();
}
function pressedBackground(){
if (backgroundFx == 'snow'){
//add 1 to make shape move down
snowY = snowY+1;
if (snowY >height){
snowY=0
}
//manipulate parameters
for (snowLocation=0; snowLocation<600; snowLocation+=30){
snowEffect(20+snowLocation,snowY)
}
} else if (backgroundFx =='rain'){
rainY= rainY+1;
if(rainY>height){
snowY=0
}
//manipulate parameters
for (rainLocation=0; rainLocation<600; rainLocation+=20){
rainEffect(20+rainLocation,rainY)
}
} else {
push();
fill(255,0,0);
text('TOO HOT!',289,79);
text('PRESS AGAIN!!',289,90);
pop();
}
}
function snowEffect(snowX,snowY){
push();
fill(127,0,255);
text('TOO COLD!',289,79);
text('PRESS AGAIN!!',289,90);
pop();
for (snowDrop=0; snowDrop <20; snowDrop++){
push();
fill(255);
ellipse(snowX+snowDrop*50,snowY-snowX,20);
pop();
}
// to cover the the empty space, minus the X value
for (snowDrop=0; snowDrop <20; snowDrop++){
push();
fill(255);
ellipse(snowX-snowDrop*50,snowY-snowX,20);
pop();
}
}
function rainEffect(rainX,rainY){
push();
fill(14,87,161);
text('TOO WET!',289,79);
text('PRESS AGAIN!!',289,90);
pop();
for (rainDrop=0; rainDrop <20; rainDrop++){
push();
fill(71,164,255);
ellipse(rainX+rainDrop*60, rainY-rainX,10)
pop();
}
//to cover the empty space, minus the x value
for (rainDrop=0; rainDrop <20; rainDrop++){
push();
fill(71,164,255);
ellipse(rainX-rainDrop*60,rainY-rainX,10);
pop();
}
}
function mousePressed(){
let backGround = ['snow','rain','sun'];
//feed in number into global state of backgroundFX
backgroundFx = random(backGround);
}