xxxxxxxxxx
141
function setup() {
createCanvas(800, 800);
eyeTicker = 0;
eyePosition = 1;
armPosition = PI + HALF_PI;
armTarget = round(random(PI, TWO_PI), 2);
clawAngle = 0;
frameRate(24);
}
function draw() {
//draw background and background elements
background(194, 254, 255);
fill( 118, 104, 86 );
noStroke();
rect(0, 700, 800, 200);
//draw curved arm
noFill();
strokeWeight(20);
stroke(75);
arc(400, 400, 700, 700, armPosition, HALF_PI);
//draw planter
noStroke();
fill( 204, 100, 82 );
ellipse(400, 740, 360, 40)
quad(200, 660, 600, 660, 580, 740, 220, 740);
fill( 227, 129, 112 );
ellipse(400, 660, 400, 40);
//draw eye
fill(120);
circle(520, 705, 60);
fill(150);
circle(530, 705, 60);
fill( 185, 255, 250 );
circle(530, 705, 40);
//if statement for eye movement and blinking
//determines if eyeposition is 1 or negative 1, draws in two different positions
if(eyePosition > 0){
fill( 71, 91, 197 );
circle(525, 697, 20);
eyeTicker++;
}
if (eyePosition < 0){
fill( 71, 91, 197 );
circle(530, 695, 20);
eyeTicker++;
}
//after a certain point, draw a circle to indicate blink and then chages eyeposition
if(eyeTicker>99 || eyeTicker<-99){
fill(150);
circle(530, 705, 40);
if(eyeTicker>100 || eyeTicker<-100){
eyeTicker= eyeTicker*-1;
eyePosition = eyePosition*-1;
}
}
//console.log(eyeTicker);
//draw soil in pot, using two arcs
fill(100, 55, 10);
arc(400, 660, 360, 65, PI, 0);
arc(400, 660, 360, 30, 0, PI);
//draw bonsai
//background leaves and branches
fill( 49, 198, 75);
ellipse(475, 350, 200, 50);
//curves for branches, setting the stroke weight high so they just look like thick branches
strokeWeight(30);
stroke(231, 186, 109);
noFill();
curve(700, 800, 370, 635, 470, 300, 1000, 600);
strokeWeight(20);
curve(370, 200, 470, 305, 600, 240, 570, 270);
curve(0, 400, 470, 305, 350, 200, 100, 200);
curve(600, 400, 370, 400, 200, 370, 200, 370);
strokeWeight(10);
curve(0, 360, 390, 360, 475, 350, 475, 350);
//traingles for roots
noStroke();
fill(231, 186, 109);
triangle(370, 650, 360, 600, 530, 650);
triangle(370, 650, 360, 620, 300, 650);
//draw leaves
fill( 144, 223, 110 );
ellipse(200, 350, 300, 75);
ellipse(300, 440, 250, 62);
ellipse(475, 200, 400, 100);
ellipse(275, 225, 300, 75);
ellipse(650, 240, 200, 60);
//animation setup, starts a translation and move centerpoint to center of canvas
translate(400,400);
//changes angle of the translation and updates arm position
//if arm reaches target, choose new random target and draw shears as closed
if(armPosition == armTarget){
armTarget = round(random(PI, TWO_PI), 2);
let angle = clawAngle * 0.01;
rotate(angle);
fill(150);
circle(0,-350, 20);
fill(200);
circle(0, -303.5, 75);
} else {
//if target is above claw position, rotate clockwise
if(armPosition < armTarget){
clawAngle ++;
let angle = clawAngle * 0.01;
rotate(angle);
armPosition = round(armPosition + 0.01, 2);
}
else{
//if target is under claw position, rotate counterclockwise
clawAngle --;
let angle = clawAngle * 0.01;
rotate(angle);
armPosition = round(armPosition - 0.01, 2);
}
//draw shears at new angle
fill(150);
circle(0,-350, 20);
fill(200);
arc(0, -303.5, 75, 75, HALF_PI+QUARTER_PI, PI + HALF_PI, OPEN);
arc(0, -303.5, 75, 75, PI + HALF_PI, QUARTER_PI, OPEN);
}
//console.log('Pos:' +armPosition);
//console.log('Target:' + armTarget);
}