bug lady; int numAphids = 10; int maxAphids = 10; bug[] aphids = new bug[maxAphids]; PFont fontScore,fontWin,fontData; int score = 0; int flag = 1; int boardWidth = 600; int sideWidth = 300; int boardHeight = 600; PImage target; int numLeaves = 200; leaf[] leaves = new leaf[numLeaves]; //PImage bg; void setup(){ frameRate(30); size(boardWidth+sideWidth,boardHeight); background(255,255,255); lady = new bug(250,250,40); for(int i =0; i boardWidth) adjustMouseX = boardWidth; // avoids ladybug wrapping right if(type ==0){ // ladybug dx=0.3*(adjustMouseX-x); dy=0.3*(mouseY-y); if(dx > 10) dx = 10; if(dx < -10) dx = -10; if(dy > 10) dy = 10; if(dy < -10) dy = -10; } if(type == 0){ // ladbug x += dx; y += dy; } else{ x+=(v*sin(theta)); y+=(v*cos(theta)); theta+=dtheta; dtheta+=(random(0.01)-0.005); timer++; if(timer == 20){ // parent timer = 0; int j=0; while(j < maxAphids && aphids[j] != null){ j++; // find null slot } // pick parent if(j < maxAphids){ aphids[j] = new bug(); aphids[j].mutCopy(this); numAphids++; } } } if(x < 0) x = boardWidth; if(x>boardWidth) x = 0; if(y < 0) y = boardHeight; if(y>boardHeight) y = 0; } void display() { if(type == 0) displaylady(); else displayaphid(); } void displaylady (){ float angle = atan(dx/dy); if(dy<0) angle=angle+PI; stroke(0,0,0); fill(255,0,0); ellipse(x,y,radius,radius); line(x+(radius-1)/2*sin(angle),y+(radius-1)/2*cos(angle),x-(radius-1)/2*sin(angle),y-(radius-1)/2*cos(angle)); fill(0,0,0); ellipse(x+(radius*0.5)*sin(angle),y+(radius*0.5)*cos(angle),radius*.25,radius*.25); ellipse(x+(radius)/4*sin(angle+PI/3),y+(radius)/4*cos(angle+PI/3),radius/5,radius/5); ellipse(x+(radius)/4*sin(angle-PI/3),y+(radius)/4*cos(angle-PI/3),radius/5,radius/5); ellipse(x+(radius)/4*sin(angle+2*PI/3),y+(radius)/4*cos(angle+2*PI/3),radius/5,radius/5); ellipse(x+(radius)/4*sin(angle-2*PI/3),y+(radius)/4*cos(angle-2*PI/3),radius/5,radius/5); } void displayaphid(){ if(type == 0) return; noStroke(); fill(0,0,0); ellipse(x+(radius*0.5)*sin(theta-0.2),y+(radius*0.5)*cos(theta-0.2),radius*.25,radius*.25); ellipse(x+(radius*0.5)*sin(theta+0.2),y+(radius*0.5)*cos(theta+0.2),radius*.25,radius*.25); fill(c); ellipse(x,y,radius,radius); } } void calcStats(){ float avgV = 0; float avgTheta = 0; float avgDtheta = 0; int count = 0; for(int i = 0; i < maxAphids; i++){ if(aphids[i] != null){ count++; avgV+=aphids[i].v; avgTheta+=aphids[i].theta; avgDtheta+=aphids[i].dtheta; } } avgV /= count; avgTheta /= count; avgDtheta /= count; textFont(fontData); text("Average Aphid Speed = " + round(avgV*10)/10.0, boardWidth+sideWidth/2.0 - 100, 50); // text("Average Aphid Turn = " + round(avgTheta*10)/10.0, boardWidth+sideWidth/2.0 - 100, 75); // text("Average Aphid Delta Turn = " + round(avgDtheta*100)/100.0, boardWidth+sideWidth/2.0 - 100, 100); } class leaf{ float x,y; float r1,r2; color c; leaf(){ x = random(-10,boardWidth); y = random(-10,height); r1 = random(50,100); r2 = random(50,100); c = color(int(random(0,50)),int(random(180,220)),int(random(0,50))); } void drawLeaf(){ stroke(c); fill(c); ellipse(x,y,r1,r2); } }