level 1
float x =100;
float y =100;
float w =60;
float h =60;
float eyeSize = 16;
void setup () {
size (500,500);
}
void draw () {
background (255);
//color depends on the distance
float d = dist (x,y,mouseX, mouseY);
color c = color (d);
//decide the movement of Zoog
float factor = constrain (mouseX/10, 0,5);//change in 0 to 5
//give the definitions to Zoog, don't put it into draw, or it changes before open the procedure
jiggleZoog (factor);
drawZoog (c);
//define the jiggle and draw
void jiggleZoog (float speed) {
x = x +random (-1,1) * speed;
y = y +random (-1,1) * speed;
x = constrain (x,0,width);
y = constrain (y,0,height);
}
void drawZoog (color eyeColor) {
ellipseMode (CENTER);
rectMode (CENTER);
//arms
for (float i = y-h*3; i<y +h/2; i +=10) {
stroke (0);
line (x -w/4,i,x+w/4,i);
}
//body
stroke (0);
fill(255);
rect(x,y,w/6,h);
//head
stroke(0);
fill(255);
ellipse (x,y-h,w,h);
//eyes
fill (eyeColor);
ellipse (x-w/3,y-h,eyeSize, eyeSize*2);
ellipse (x+w/3,y-h,eyeSize, eyeSize*2);
//legs
stroke (0);
line(x-w/12, y+h/2, x-w/4, y+h/2+10);
line(x+w/12, y+h/2, x+w/4, y+h/2+10);
}
}
2016年03月02日 07点03分

