// The class for our "line", contains DNA sequence, fitness value, position on screen class Line { DNA genes; //line's DNA float fitness=0; //how good is this line? int x,y; //position on screen float s;//////////////scale of lines String typing=""; int r,g,b; Line(DNA d, int x_, int y_,int rr,int gg,int bb,float s_) { genes = d; x = x_; y = y_; s = s_; r=rr;g=gg;b=bb; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////render the line void render() { /* here, we are using the elements from the "genes" to pick properties for the line.*/ float x1 = genes.getGene(0); float y1 = genes.getGene(1); float x2 = genes.getGene(2); float y2 = genes.getGene(3); float x3 = genes.getGene(4); float y3 = genes.getGene(5); float x4 = genes.getGene(6); float y4 = genes.getGene(7); float x5 = genes.getGene(8); float y5 = genes.getGene(9); float x6 = genes.getGene(10); float y6 = genes.getGene(11); float x7 = genes.getGene(12); float y7 = genes.getGene(13); float x8 = genes.getGene(14); float y8 = genes.getGene(15); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////once we calculate all the above properties, we use those variables to draw line. noFill(); strokeWeight(2); stroke(r,g,b); pushMatrix(); translate(x,y); scale(s); beginShape(); curveVertex(x1,y1); curveVertex(x1,y1); curveVertex(x2,y2); curveVertex(x3,y3); curveVertex(x3,y3); endShape(); beginShape(); curveVertex(x3,y3); curveVertex(x3,y3); curveVertex(x4,y4); curveVertex(x5,y5); beginShape(); curveVertex(x3,y3); curveVertex(x3,y3); curveVertex(x4,y4); curveVertex(x5,y5); curveVertex(x6,y6); curveVertex(x6,y6); endShape(); beginShape(); curveVertex(x6,y6); curveVertex(x6,y6); curveVertex(x7,y7); curveVertex(x7,y7); //curveVertex(x8,y8); //curveVertex(x8,y8); endShape(); beginShape(); curveVertex(x6,y6); //curveVertex(x6,y6); curveVertex(x7,y7); curveVertex(x8,y8); curveVertex(x8,y8); endShape(); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////draw the wheel stroke(255); 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); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////draw the rectangle under the car line noFill(); stroke(0,57,79); strokeWeight(2); rect(x1+248,y1+75,100,50); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////input the fitness value to the screen textFont(font); fill(255); textSize(30); textAlign(LEFT); text(typing,x1+268,y1+100); popMatrix(); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////translate the String value to float value float getFitness() { fitness=Float.parseFloat(typing); return fitness; } DNA getGenes() { return genes; } void plot() { float x1 = genes.getGene(0); float y1 = genes.getGene(1); float x2 = genes.getGene(2); float y2 = genes.getGene(3); float x3 = genes.getGene(4); float y3 = genes.getGene(5); float x4 = genes.getGene(6); float y4 = genes.getGene(7); float x5 = genes.getGene(8); float y5 = genes.getGene(9); float x6 = genes.getGene(10); float y6 = genes.getGene(11); float x7 = genes.getGene(12); float y7 = genes.getGene(13); float x8 = genes.getGene(14); float y8 = genes.getGene(15); smooth(); stroke(r,g,b); noFill(); pushMatrix(); translate(100,0); beginShape(); curveVertex(x1,y1); curveVertex(x1,y1); curveVertex(x2,y2); curveVertex(x3,y3); curveVertex(x3,y3); endShape(); beginShape(); curveVertex(x3,y3); curveVertex(x3,y3); curveVertex(x4,y4); curveVertex(x5,y5); curveVertex(x6,y6); curveVertex(x6,y6); endShape(); beginShape(); curveVertex(x6,y6); curveVertex(x6,y6); curveVertex(x7,y7); curveVertex(x7,y7); //curveVertex(x8,y8); //curveVertex(x8,y8); endShape(); beginShape(); curveVertex(x6,y6); //curveVertex(x6,y6); curveVertex(x7,y7); curveVertex(x8,y8); curveVertex(x8,y8); endShape(); popMatrix(); } }