// Andre Stubbe 2003 BImage pic, pic1, pic2, pic3; color brown, black, orange, blue; int num; Fly fly[]; Menu menu; void setup() { size(320, 240); framerate(40); smooth(); ellipseMode(CENTER_DIAMETER); pic1 = loadImage("background1.jpg"); pic2 = loadImage("background2.jpg"); pic3 = loadImage("background3.jpg"); pic = pic1; brown = #524741; black = #111111; orange = #FB8602; blue = #04B4DA; num = 3; fly = new Fly[100]; for(int i=0; i= height-36) { if(mouseX > 175 && mouseX < 199) pic = pic1; else if(mouseX > 199 && mouseX < 223) pic = pic2; else if(mouseX > 223 && mouseX < 247) pic = pic3; else if(mouseX > 259 && mouseX < 282) addFly(); else if(mouseX > 282 && mouseX < 306) removeFly(); } // dirty code (for first fly) fill(blue); ellipse(fly[0].x,fly[0].y,4,4); noFill(); stroke(brown); ellipse(fly[0].p1x,fly[0].p1y,3,3); ellipse(fly[0].p2x,fly[0].p2y,3,3); ellipse(fly[0].p3x,fly[0].p3y,3,3); menu.update(); } void addFly(){ if(num < 100){ fly[num] = new Fly(160,120,8,8,random(radians(360)),random(0,0.1),random(2,5)); num++; } } void removeFly(){ if(num >3) num--; // ? how can i remove an object ? } class Fly { int x, y, w, h; float xdistance, ydistance, direction, speed, minSpeed, maxSpeed; float p1x, p1y, p2x, p2y, p3x, p3y; color c1,c2,c3; float b1, b2, b3; Fly(int X, int Y, int W, int H, float Dir, float Min, float Max){ x = X; y = Y; w = W; h = H; direction = Dir; minSpeed = Min; maxSpeed = Max; speed = random(minSpeed,maxSpeed); } int getColor(float X, float Y){ int x = int(X); int y = int(Y); return int(get(x,y)); } void newDirection(){ p1x = x+(cos(direction-radians(25))*10); p1y = y+(sin(direction-radians(25))*10); p2x = x+(cos(direction)*10); p2y = y+(sin(direction)*10); p3x = x+(cos(direction+radians(25))*10); p3y = y+(sin(direction+radians(25))*10); c1 = getColor(int(p1x), int(p1y)); c2 = getColor(int(p2x), int(p2y)); c3 = getColor(int(p3x), int(p3y)); // Fly at left eye if(c1 == black){direction += -radians(25); speed = minSpeed; // Fly at center eye }else if(c2 == black){ direction = direction; speed = minSpeed; // Fly at right eye }else if(c3 == black){ direction += radians(25); speed = minSpeed; // look for brighter area }else { // get brightness b1 = brightness(c1); b2 = brightness(c2); b3 = brightness(c3); // set direction if(b1 > b2 && b1 > b3) direction += random(-radians(25),-radians(10)); else if(b3 > b2 && b3 > b1) direction += random(radians(25),radians(10)); else direction += random(-radians(10), radians(10)); } } void newSpeed(){ speed = speed + random(-1,1); speed = constrain(speed, minSpeed, maxSpeed); } void newPosition (){ xdistance = cos(direction)*speed; ydistance = sin(direction)*speed; x += xdistance; y += ydistance; } void stayInStage(){ if(x < 0 || x > width || y < 0 || y > height) direction += radians(180); } void draw(){ noStroke(); fill(black); ellipse(x, y, w, h); } void update(){ newSpeed(); newDirection(); newPosition(); stayInStage(); draw(); } } class Menu { float x, y, yNew, damping; Menu(float X, float Y, float D){ x = X; y = Y; damping = D; yNew = y; } void draw(){ // Layer noStroke(); fill(brown); rect(x, y, width, 36); // Arrow stroke(orange); noFill(); line(width/2, y+3, width/2+4, y+7); line(width/2, y+3, width/2-3, y+6); // fly[0] view stroke(brown); fill(fly[0].c1); rect(x+12,y+13, 24, 12); fill(fly[0].c2); rect(x+36,y+13, 24, 12); fill(fly[0].c3); rect(x+60,y+13, 24, 12); // Background Icons image(pic1, x+175, y+13, 24, 12); image(pic2, x+199, y+13, 24, 12); image(pic3, x+223, y+13, 24, 12); // More/less Flys noFill(); stroke(orange); // plus rect(259, y+13, 24, 12); line(269, y+19, 274,y+19); line(271, y+17, 271,y+22); //minus rect(283, y+13, 24, 12); line(293, y+19, 298,y+19); } void checkMouse(){ float yD = dist(0, height, 0, mouseY); if(yD >= 20) yNew = height-12; else yNew = height-36; } void newPosition(){ y += (yNew - y)*damping; } void update(){ if(round(abs(yNew -y)) != 0) newPosition(); else checkMouse(); draw(); } }