/* Matt Martell IAT 800 - Dr. Christopher Shaw Due Oct. 6, 2008 A2-13 - Program your moving elements from A2-09 but use classes to represent the two visual elements. */ //Box that moves at random class BoxMove { float xPos; float yPos; //draw method void drawMe() { xPos = xPos + random(25)*2; xPos++; if(xPos>width) xPos=0; yPos = yPos + random(25)/2; yPos++; if(yPos>height) yPos=0; rect (xPos, yPos, 15,15); } } //moving box in relation to mouse position class BoxMouse { float uPos; float wPos; //draw method void drawMe() { uPos = mouseX/random(10) + random(5)/2; uPos++; if(uPos>width) uPos=0; wPos = mouseY/random(10) + random(5)/2; wPos++; if(wPos>height) wPos=0; rect (uPos, wPos, 15,15); } } BoxMove[] bm = new BoxMove[2]; BoxMouse[] bm2 = new BoxMouse[1]; void setup() { background (3444); size(400,400); smooth(); stroke(230,230,250); frameRate(7); for (int i=0; i < 2; i++) { bm[i] = new BoxMove(); } for (int f=0; f < 1; f++) bm2[f] = new BoxMouse(); } void draw() { background (3444); bm[0].drawMe(); bm2[0].drawMe(); }