//Genetic Algorithm for math //developed from: // GeneticAlgorithm ga; int target = 42; int newTarget = 0; int keyDigit = 0; String targetString = "target:42"; String printout = "calculating"; String newTargetString = ""; PFont font; boolean found = false; void setup(){ size(500, 100); font = loadFont("ArialMT-30.vlw"); textFont(font, 30); ga = new GeneticAlgorithm(42); } void draw(){ background(100); text(targetString, 0, 30); text(printout, 0, 60); text(newTargetString, 0, 90); if(!ga.found && !found){ printout = "calculating - generations:"+ga.generation; ga.propagate(); } else{ found = true; newTargetString = "enter 2 digit target"; } } void keyPressed(){ if(ga.found){ if(Character.isDigit(key)){ if(keyDigit == 0){ newTarget = 0; newTarget += (key - '0') * 10; targetString = "target:"+key; keyDigit++; } else{ newTarget += key - '0'; keyDigit = 0; ga = new GeneticAlgorithm(newTarget); targetString += key; target = newTarget; newTargetString = ""; found = false; printout = "calculating"; } } } }