/* IAT 813: Artificial Intelligence in Computational Art & Design Dr. Steve DiPaola Xiao Zhang CAR FORM LINE GENERATION CREDITS: Genetic Algorithm Library for Processing - by Daniel Shiffman - http://www.shiffman.net/teaching/nature/ga/ - licensed under the GNU Lesser General Public License (http://www.gnu.org/copyleft/lesser.html) ControlP5 UI Library - by Andreas Schlegel - http://www.sojamo.de/libraries/controlP5/ - licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)*/ Population p; DNA[]d=new DNA[9] ; String[]saving={"","","","","","","","",""}; int j; ControlP5 controlP5; PFont font; void setup() { size(1300,900); controlP5 = new ControlP5(this); font = loadFont("Discognate-72.vlw"); controlP5.addButton(" EVOLVE NEW GENERATION ",8,1085,120,177,30); d[0]= new DNA (10,183,31,151,160,132,261,78,415,78,508,128,570,130,580,176);////////////////////////////audi a6 1996 //d[1]= new DNA (10,183,37.5,155,162,133.5,261.5,85,415.5,84,517,122,562,127,580,176); //d[2]= new DNA (10,183,36.6,151.85,169.95,131.15,261.5,85.5,416.5,83,517,122.25,562.5,130.75,580,176); //d[3]= new DNA (10,183,34.5,151,162,131,260,83,423,87,517,125.5,561,133,580,176); //d[4]= new DNA (10,190,34.5,151,169,131.4,260.25,85.2,426.15,85.75,526.5,125.5,567.4,129.5,580,176);///////////////////////////////////////////////////////////////old example d[1]= new DNA (10,167.2,38,152,152,135,267.5,83,413.5,82.5,528.5,127.5,572.5,129,582,169);////////////////////////////////////2007 Chrysler d[2]= new DNA (10,173,34,161,166.5,132.2,260,81,405,74,516.5,118.5,573.2,124.8,577,172);///////////////////////////////////////2006 Cadilac d[3]= new DNA (10,171,37,158,166.5,134.5,261.5,84,412.5,80.5,518,121,576,126.8,577,169);//////////////////////////////////////////2008 BMW 5 d[4]= new DNA (10,169,38.5,157,153,136.7,259.4,86,406.2,82.6,507,116,570,125.5,574,179);////////////////////////////////////////////////////2008 ford d[5]= new DNA (10,183,35.25,154.25,174.65,131.25,276.55,80,423.75,79.55,520.25,118.5,573.9,124.6,578,172);/////////////////////////////////2004 bmw 502i d[6]= new DNA (10,183,37.5,159.75,147.6,137.2,262,89,415.5,84,531.45,125.5,569.2,131.25,574,176);////////////////////////////////////////2005 citroen-c5 //d[7]= new DNA (10,190,32.55,155.9,181.05,128.55,271.9,86.8,431.7,85.35,516.1,121.1,563.9,127.75,580,176);//////////////////////////////// d[7]= new DNA (10,171,37,157.5,180.7,134.2,271.2,85,420.5,82,515.5,124,575,126.2,583,173);//////////////////////////////////////////////////////////////////////new example 2006 benz e class d[8]= new DNA (10,183,34.87,151.55,155.65,131,265.64,80,414.96,82.08,514.79,119.09,567.31,127.02,575,176);///////////////2003 Nissan Teana p = new Population(0.4,d); } void draw() { smooth(); background(0); textFont(font); fill(139,163,175); textSize(48); text("car form line generation", 860, 80);//////////////////////////////////////////////////////////////////"name" textSize(72); textAlign(LEFT); text(p.getGenerations(),1147,210);//////////////////////////////////////////////////////////////display the number of generations noFill(); stroke(0,57,79); strokeWeight(1); line(0,300,1300,300); //stroke(255); //line(265,120,1185,120); pushMatrix(); translate(100,0); noFill(); stroke(255); strokeWeight(2); line (39.453,217.506,102.637,220.296); ellipse(151.935,214.709,86.473,100.893); line(194.99,219.473,427.713,219.473); ellipse(468.987,212.962,83.773,96.002); line(518.211,220.961,574.467,214.656); fill(0); stroke(0); rect(99.403,224.416,108,48); rect(418.628,222.658,111.253,55.852); popMatrix(); p.display();////////////////////////////////////////////////////////////////////////////////////display the lines noStroke(); fill(236,27,35); rect(240,250,20,20); fill(255,241,0); rect(280,250,20,20); fill(40,180,114); rect(320,250,20,20); fill(0,173,238); rect(360,250,20,20); fill(46,48,145); rect(400,250,20,20); fill(235,0,139); rect(440,250,20,20); fill(144,38,142); rect(480,250,20,20); fill(246,146,29); rect(520,250,20,20); fill(200,200,200); rect(560,250,20,20); //////////////////////////////////////////////////////////////////////////////////////////////////// If the button is clicked, evolve next generation } void mouseClicked() { if(mouseX<265&&mouseX>205&&mouseY<470&&mouseY>440){ j=1; } if(mouseX<685&&mouseX>625&&mouseY<465&&mouseY>435) { j=2; } if(mouseX<1105&&mouseX>1045&&mouseY<465&&mouseY>435) { j=3; } if(mouseX<265&&mouseX>205&&mouseY<665&&mouseY>635){ j=4; } if(mouseX<685&&mouseX>625&&mouseY<665&&mouseY>635) { j=5; } if(mouseX<1105&&mouseX>1045&&mouseY<670&&mouseY>640) { j=6; } if(mouseX<265&&mouseX>205&&mouseY<875&&mouseY>845){ j=7; } if(mouseX<685&&mouseX>625&&mouseY<875&&mouseY>845) { j=8; } if(mouseX<1105&&mouseX>1045&&mouseY<870&&mouseY>840) { j=9; } if(mouseX<1262&&mouseX>1085&&mouseY<150&&mouseY>120) { p.naturalSelection(); p.generate(); } } void keyPressed() { if(j==1) { if (keyCode == BACKSPACE) { saving[0]=""; }else{ saving[0] = saving[0] + key; } } if(j==2) { if (keyCode == BACKSPACE) { saving[1]=""; }else{ saving[1] = saving[1] + key; } } if(j==3) { if (keyCode == BACKSPACE) { saving[2]=""; }else{ saving[2] = saving[2] + key; } } if(j==4) { if (keyCode == BACKSPACE) { saving[3]=""; }else{ saving[3] = saving[3] + key; } } if(j==5) { if (keyCode == BACKSPACE) { saving[4]=""; }else{ saving[4] = saving[4] + key; } } if(j==6) { if (keyCode == BACKSPACE) { saving[5]=""; }else{ saving[5] = saving[5] + key; } } if(j==7) { if (keyCode == BACKSPACE) { saving[6]=""; }else{ saving[6] =saving[6] + key; } } if(j==8) { if (keyCode == BACKSPACE) { saving[7]=""; }else{ saving[7] =saving[7] + key; } } if(j==9) { if (keyCode == BACKSPACE) { saving[8]=""; }else{ saving[8] = saving[8] + key; } } }