bunny bun1; //declare bun1 as first bunny bunny bun2; // declare bun2 as second bunny void setup() { size(500, 300); framerate(30); bun1 = new bunny (200, 200, 2, 5, color (160, 153, 255)); bun2 = new bunny (288, 315, 5, 2, color (251, 128, 204)); } //____________________________________DRAW_________________________________________________________ void draw(){ //draw bunny background(255); //What is the difference between declaring the background in setup() vs in draw()? bun1.draw_bunny(); bun1.move_bunny(); bun2.draw_bunny(); bun2.move_bunny(); } //____________________________________CLASS_________________________________________________________ class bunny{ int xpos; int ypos; int xspeed; int yspeed; color body_color; int body_width = 25; int body_height = 25; int head_size = 25; int eye_width = 5; int eye_height = 5; int paw_width = 15; int paw_height = 15; int ear_width = 15; int ear_height = 60; int foot_width = 15; int foot_height = 15; int left_bnd, right_bnd, top_bnd, bottom_bnd; //applet boundaries bunny(int xp, int yp, int xs, int ys, color bc){ xpos = xp; //set initial x position ypos = yp; //set initial y position xspeed = xs; //set initial speed on x-axis yspeed = ys; //set initial speed on y-axis body_color = bc; //set color of bunny's body right_bnd = width - (body_width/2)-15; left_bnd = (body_width/2)+15; top_bnd = (body_height/2) + head_size + 30; bottom_bnd = height - (body_height+foot_height+10); } //____________________________________DRAW_________________________________________________________ void draw_bunny(){ noStroke(); smooth(); fill(body_color);//color "blue" _______________________ ellipse(xpos, ypos, head_size, head_size); //head ellipse(xpos-10, ypos-40, ear_width, ear_height);//left ear ellipse(xpos+10, ypos-40, ear_width, ear_height);//right ear ellipse(xpos+10,ypos+48,foot_width,foot_height);//left foot ellipse(xpos-10,ypos+48,foot_width,foot_height);//right foot ellipse(xpos+20,ypos+25,paw_width,paw_height);//left paw ellipse(xpos-20,ypos+25,paw_width,paw_height);//right paw fill(255); //color "white" _______________________ ellipse(xpos-10, ypos-40, ear_width - 5, ear_height - 10);//left ear ellipse(xpos+10, ypos-40, ear_width - 5, ear_height - 10);//right ear ellipse(xpos-5,ypos,eye_width,eye_height);//left eye ellipse(xpos+5,ypos,eye_width,eye_height);//right eye triangle(xpos-2, ypos+7, xpos+1, ypos+10, xpos+5, ypos+7); //nose fill(160, 153, 255);//color "lavendar" _______________________ rect(xpos-12,ypos+15,body_width,body_height);//body } //____________________________________MOVE_________________________________________________________ void move_bunny(){ xmove(); ymove(); } void xmove() { xpos += xspeed; if (xpos > right_bnd) { xpos = right_bnd; xspeed *= -1; } else if (xpos < left_bnd) { xpos = left_bnd; xspeed *= -1; } } void ymove() { ypos += yspeed; if (ypos > bottom_bnd) { ypos = bottom_bnd; yspeed *= -1; } else if (ypos < top_bnd) { ypos = top_bnd; yspeed *= -1; } } }