xxxxxxxxxx
144
let x=0; //Translation x-coordinate
let y=0; //Translation y-coordinate
let armLength=0; //Arm length
let handY=140; //Hands' y-coordinate
let armConnectorY=140; //Arm connectors' y-coordinate
let feetY=250; //Feet y-coordinate
let legConnectorY=250; //Leg connectors' y-coordinate
let legLength=0; //Leg length
let valueR=192;
let valueG=253;
let valueB=255;
let scaleVar=0.1;
function setup() {
createCanvas(400, 400);
noStroke();
rectMode(CENTER);
}
function draw() {
background(225);
translate(x,y) //Translation parameters
scale(scaleVar);
/*----------------------------------------------------------------------*/
/* Robot Arms */
//Arms
push(); //Start CORNER rectMode
rectMode(CORNER);
fill(208, 209, 255); //Light Purple
rect(102, 140, 18, armLength); //Left Arm
rect(280, 140, 18, armLength); //Right Arm
pop(); //Stop CORNER rectMode
//Shoulders
fill(200, 231, 255); //Light Blue
rect(107.5, 140, 25, 22, 40, 0, 0, 6); //Left Shoulder
rect(292.5, 140, 25, 22, 0, 40, 6, 0); //Right Shoulder
//Hands
rect(111, handY, 25, 22, 5, 5, 5, 5); //Left Hand
rect(289, handY, 25, 22, 5, 5, 5, 5); //Right Hand
//Arm Connectors
rect(111, armConnectorY, 25, 22, 5, 5, 5, 5); //Left Arm Connector
rect(289, armConnectorY, 25, 22, 5, 5, 5, 5); //Right Arm Connector
/*----------------------------------------------------------------------*/
/* Robot Legs */
push(); //Start CORNER rectMode
rectMode(CORNER);
fill(208, 209, 255); //Light Purple
rect(142, 240, 18, legLength); //Left Leg
rect(240, 240, 18, legLength); //Right Leg
pop(); //Stop CORNER rectMode
//Leg Connectors
fill(200, 231, 255); //Light Blue
rect(151, legConnectorY, 25, 22, 5, 5, 5, 5); //Left Leg Connector
rect(249, legConnectorY, 25, 22, 5, 5, 5, 5); //Left Leg Connector
//Feet
rect(151, feetY, 45, 22, 5, 5, 5, 5); //Left Feet
rect(249, feetY, 45, 22, 5, 5, 5, 5); //Right Feet
/*----------------------------------------------------------------------*/
/* Robot Body */
fill(243, 196, 251); //Light Pink
rect(200, 160, 160, 280, 80);
/*----------------------------------------------------------------------*/
/* Robot Head */
//Face
fill(222, 170, 255); // Purple
rect(200, 85, 110, 60, 30);
//Eyes
fill(valueR, valueG, valueB); //Light Aqua - also applied to Body Light Ring & Head Lights
rect(172.5, 85, 5, 30); //Left Eye
rect(227.5, 85, 5, 30); //Right Eye
//Body Light Ring
rect(200, 140, 160, 10);
//Head Lights
rect(112.5, 100, 15, 20, 10, 0, 0, 10); //Left Light
rect(287.5, 100, 15, 20, 0, 10, 10, 0); //Right Light
fill(222, 170, 255); // Purple
rect(120, 100, 5, 30); //Left Connector
rect(280, 100, 5, 30); //Right Connector
}
/*----------------------------------------------------------------------*/
/* Use keyPressed to make the robot grow */
function keyPressed() {
/* Grow up */
if (keyCode === UP_ARROW && scaleVar<=0.9) {
scaleVar = scaleVar+0.1;
}
/* Shrink Down */
if (keyCode === DOWN_ARROW && scaleVar>=0.2) {
scaleVar = scaleVar-0.1;
}
}
/*----------------------------------------------------------------------*/
/* Use mouseDragged to make the robot dance */
function mouseDragged() {
/* Randomize colors to create blinking effect on eyes and lights */
/*valueR = random(0,255);
valueG = random(0,255);
valueB = random(0,255);*/ //remember to reactivate this once animation is done
x = mouseY-200; //Move robot's position along the x axis
armLength = mouseY-200; //Move robot's arms up and down
//Make legs appear
if (legLength<=140 && mouseY>=40) {
legLength = mouseY-200;
}
handY = 140+armLength; //Move hands along with the arms
armConnectorY = 140+armLength/2; //Move arm connectors along with the arms
feetY = 250+legLength; //Move feet along with the arms
legConnectorY = 250+legLength/2; //Move leg connectors along with the arms
}