/************************************* * Author: Jonathan Seguin * Last Modified: March 3rd 2010 * Problem Set: 2 * Question: 5 & 6 **************************************/ //Description: Draws a cute spider that //might just move! class Spider { //Variables color bodyColour; // body colour color eyeColour; // eye colour color legColour; // leg colour int x, y; // spider position float scaling; // spider size. //Constructor // x,y = position // scaling = size relative to original Spider (int x, int y, float scaling, color bodyColour, color eyeColour, color legColour) { this.x = x; this.y = y; this.bodyColour = bodyColour; this.eyeColour = eyeColour; this.legColour = legColour; this.scaling = scaling; } //Functions //Makes spider a leg //template draws: left bottom //Parameters: x = x position of leg, y = y position of leg private void legLeft(int x,int y) { pushMatrix(); translate(x,y); line(-90, -10, -70, 0); line(-90, -10, -130, 50); popMatrix(); } //Makes spider a leg //template draws: Right Bottom //Parameters: x = x position of leg, y = y position of leg private void legRight(int x,int y) { pushMatrix(); translate(x,y); line(90, -10, 70, 0); line(90, -10, 130, 50); popMatrix(); } //draw thread spider hangs from void thread() { pushMatrix(); translate(x,0); scale (scaling,1); for (int a = 0; a < 4; a++) { stroke(255,a+1*40); strokeWeight(4*a); line (0, 0, 0, map(mouseY,0, height, 5,height)); } popMatrix(); } //Draws a cute spider void spider() { pushMatrix(); translate(x,y); scale (scaling); noStroke(); //Body fill(bodyColour); ellipse (0,0 , 140,100); ellipse (0, -60, 150,140); //Eyes fill(eyeColour); ellipse (-35, 0,20,20); ellipse (35, 0,20,20); fill(255); ellipse (-35, 0,10,10); ellipse (35, 0,10,10); //Blush fill (255,50,150,100); ellipse (-35, +20, 35,15); ellipse (35, +20, 35,15); ellipse (-35, +20, 25,8); ellipse (35, 20, 25,8); //Mouth stroke(0); strokeWeight(3); line(0, 35, 5, 28); line(0, 35, -5, 28); //legs Left Side stroke(legColour); legLeft(0,0); legLeft(4,-35); legLeft(0,-70); legLeft(10,-105); //Legs Right Side legRight(0,0); legRight(-4,-35); legRight(0,-70); legRight(-11,-105); popMatrix(); } } // end Spider