void draw_top() { int transx = 0; int transy = 0; fill(topc); noStroke(); rect(0,0,width,frame); // logo smooth(); stroke(redc); noFill(); rect(5,5,frame-10, frame-10); fill(redc); textFont(trebuchet16, 16); text("L-GARDEN",22,20); pushMatrix(); translate(frame/2,frame/2+10); rect(-5,-5,10,50); rotate(PI*0.75); rect(-5,-5,10,50); noFill(); strokeWeight(5.0); stroke(redc); ellipse(-38,0,25,25); fill(redc); noStroke(); rotate(PI*0.5); rect(-5,-5,10,32); popMatrix(); strokeWeight(1.0); noSmooth(); // mode stroke(redc); noFill(); rect(5,5,frame-10, frame-10); fill(white); textFont(trebuchet16, 16); if(automatic) text("AUTOMATIC MODE", frame+10, 25); else text("MANUAL MODE", frame+10, 25); bt_switch.draw(); fill(white); textFont(lucida, 11); if(automatic) { bt_run.draw(); text("GENERATION",boxw/2,height-boxw/2); textFont(trebuchet48,48); text(generation, boxw/2+85,height-boxw/2); } transy = 30; transx = frame; //randomize stroke(redc); noFill(); rect(transx+5,transy+5,90,frame-40); fill(redc); textFont(lucida, 11); text("POPULATION", transx+10, transy+20); bt_randomize.draw(); bt_plants.draw(); //fitness transx+=90; stroke(redc); noFill(); rect(transx+5,transy+5,150,frame-40); fill(redc); textFont(lucida, 11); text("FITNESS",transx+10, transy+20); bt_measure.draw(); fill(white); textFont(pixelfont, 8); text(fitness_display , transx+10, transy+76); textFont(pixelfont, 8); if(displfitness) text("bst "+nfc(f_best,1)+" av "+nfc(f_av,1),transx+65,transy+19); for(int i=0; i<18; i++) bt_fitness[i].draw(); //selection transx+=150; stroke(redc); noFill(); rect(transx+5,transy+5,160,frame-40); fill(redc); textFont(lucida, 11); text("SELECTION", transx+10, transy+20); bt_select.draw(); bt_clear.draw(); fill(white); textFont(pixelfont, 8); if(automatic) text("Survivalrate", transx+10, transy+38); if(automatic) text(untouched, transx+115, transy+38); text(survivalrate, transx+115, transy+52); text("Parentrate", transx+10, transy+52); if(automatic) sl_survrate.draw(); sl_parentrate.draw(); //reproduction transx+=160; stroke(redc); noFill(); rect(transx+5,transy+5,150,frame-40); fill(redc); textFont(lucida, 11); text("REPRODUCTION", transx+10, transy+20); bt_reproduce.draw(); fill(white); textFont(pixelfont, 8); text("Crossover", transx+10, transy+38); text(prob_crossover, transx+115, transy+38); text(prob_mutation, transx+115, transy+52); text("Mutation", transx+10, transy+52); sl_crossrate.draw(); sl_mutrate.draw(); //display transx+=160; stroke(redc); noFill(); rect(transx+5,transy+5,100,frame-40); fill(redc); textFont(lucida, 11); text("DISPLAY", transx+10, transy+20); fill(white); textFont(pixelfont, 8); text("generation", transx+10, transy+38); text("amount", transx+10, transy+63); display_generation.draw(); display_number.draw(); textFont(lucida, 11); /* if(automatic) text("ON AUTORUN",100,20); fill(white); text("BEST", width-150,20); text(f_best,width-90,20); text("AVERAGE", width-150,40); text(f_av, width-90,40); */ } void check_top() { bt_run.check(); bt_switch.check(); if(!run || !automatic) { bt_clear.check(); bt_plants.check(); bt_randomize.check(); bt_reproduce.check(); bt_measure.check(); bt_select.check(); for(int i=0; i<18; i++) bt_fitness[i].check(); int overbtn = -1; for(int i=0; i<18; i++) if(bt_fitness[i].over) overbtn = i; fitness_display = ""; switch(overbtn) { case 0: fitness_display = "string length"; break; case 1: fitness_display = "ratio"; break; case 2: fitness_display = "max height"; break; case 3: fitness_display = "max width"; break; case 4: fitness_display = "grow high"; break; case 5: fitness_display = "dim 200"; break; case 6: fitness_display = "dim 500"; break; case 7: fitness_display = "dim 1000"; break; case 8: fitness_display = "+ lines"; break; case 9: fitness_display = "+ arcs"; break; case 10: fitness_display = "+ pushes"; break; case 11: fitness_display = "- lines"; break; case 12: fitness_display = "- circles"; break; case 13: fitness_display = "- jumps"; break; case 14: fitness_display = "- rotmax"; break; case 15: fitness_display = "- rotations"; break; case 16: fitness_display = "- not drawing"; break; case 17: fitness_display = "+ drawing"; break; } if(automatic) sl_survrate.check(); sl_parentrate.check(); sl_crossrate.check(); sl_mutrate.check(); if(sl_crossrate.over) prob_crossover = sl_crossrate.currvalue; else if(sl_mutrate.over) prob_mutation = sl_mutrate.currvalue; else if(automatic && sl_survrate.over) { untouched = sl_survrate.currvalue; top = int(t * untouched); } else if(sl_parentrate.over) { pp = int(t * survivalrate); survivalrate = sl_parentrate.currvalue; if(automatic) { sl_survrate.maxvalue = sl_parentrate.currvalue; sl_survrate.reset(); untouched = sl_survrate.currvalue; top = int(t * untouched); } pmax = pp; } display_generation.check(); display_number.check(); } } boolean click_top() { boolean clicked = false; if(bt_switch.over) { switch_mode(); clicked = true; } else if(bt_plants.over) { plant(); clicked=true; } else if(bt_run.over) { run = (run) ? false : true; bt_run.n = (run) ? "STOP" : "RUN"; clicked = true; } else if(bt_randomize.over) { randomize(); clicked = true; } else if(bt_reproduce.over) { if(pmax != 0) { evolve(); } clicked = true; } else if(bt_measure.over) { measure_fitness(); clicked = true; } else if(bt_select.over) { oldparents = false; p=pp; pmax=p; rank(); clicked = true; } else if(bt_clear.over) { clear(); p=0; pmax = 0; clicked = true; } else if(display_generation.over) { g = display_generation.currint; } else if(display_number.over) { displgen = display_number.currint; calc_size(); replace(); } else { int overbtn = -1; for(int i=0; i<18; i++) { if(bt_fitness[i].over) { overbtn = i; bt_fitness[i].n = (bt_fitness[i].n=="*") ? " " : "*"; } } switch(overbtn) { case 0: bt_f_length = (bt_f_length) ? false : true; break; case 1: bt_f_ratio = (bt_f_ratio) ? false : true; break; case 2: bt_f_maxh = (bt_f_maxh) ? false : true; break; case 3: bt_f_maxw = (bt_f_maxw) ? false : true; break; case 4: bt_f_growh = (bt_f_growh) ? false : true; break; case 5: bt_f_dim200 = (bt_f_dim200) ? false : true; break; case 6: bt_f_dim500 = (bt_f_dim500) ? false : true; break; case 7: bt_f_dim1000 = (bt_f_dim1000) ? false : true; break; case 8: bt_f_linesp = (bt_f_linesp) ? false : true; break; case 9: bt_f_arc = (bt_f_arc) ? false : true; break; case 10: bt_f_push = (bt_f_push) ? false : true; break; case 11: bt_f_linesn = (bt_f_linesn) ? false : true; break; case 12: bt_f_circle = (bt_f_circle) ? false : true; break; case 13: bt_f_jump = (bt_f_jump) ? false : true; break; case 14: bt_f_rotmax = (bt_f_rotmax) ? false : true; break; case 15: bt_f_rot = (bt_f_rot) ? false : true; break; case 16: bt_f_notdraw = (bt_f_notdraw) ? false : true; break; case 17: bt_f_draw = (bt_f_draw) ? false : true; break; } } return clicked; } void init_top() { bt_switch = new Button(frame+220, 12, "SWITCH MODE", 92, 15); bt_run = new Button(frame+170, 12, "STOP", 40, 15); bt_randomize = new Button(133, 95, "RANDOMIZE", 77, 15); bt_plants = new Button(166,75, "SEEDS", 44,15); bt_reproduce = new Button(593, 95, "REPRODUCE", 77, 15); bt_measure = new Button(298, 95, "MEASURE", 62, 15); bt_select = new Button(418, 95, "SELECT FITTEST", 102, 15); bt_clear = new Button(370, 95, "CLEAR", 45,15); bt_fitness = new Button[18]; bt_back = new Button(width-100,height-80,"BACK",40,15); bt_replay = new Button(width-160,height-80, "REPLAY",50,15); for(int i=0; i<18; i++) { bt_fitness[i] = new Button(220+16*(i%9), (int)(i/9)*16 +58, " ", 12,12); if(i<2) bt_fitness[i].n="*"; } //sl_survrate, sl_parentrate, sl_crossrate, sl_mutrate sl_survrate = new hslider(440,60,untouched,0.0,0.3,30,9); sl_parentrate = new hslider(440,74,survivalrate,0.05,0.5,30,9); sl_crossrate = new hslider(590,60,prob_crossover,0.0,1.0,40,9); sl_mutrate = new hslider(590,74,prob_mutation,0.0,1.0,40,9); //display_generation, display_number display_generation = new hsteps(690,72,2,1,5,10); display_number = new hsteps(690,97,1,1,3,10); }