// Our fonts for the text display PFont font48, font16; // Phrase to attempt to evolve into String targetPhrase; // Size of the population of DNA objects int populationSize; // rate of mutation (between 0.0 and 1.0) float mutationRate; // The population control object Population populus; void setup() { // setup the environment size(600, 300); background(0); // load our fonts font48 = loadFont("Courier-48.vlw"); font16 = loadFont("HelveticaNeue-16.vlw"); // setup our control variables targetPhrase = "More is different"; populationSize = 100; mutationRate = 0.01f; // create the population // The parameters are: // targetPhrase - The phrase to evolve towards // mutationRate - The rate of genetic mutation // populationSize - Maximum population of the system populus = new Population(targetPhrase, mutationRate, populationSize); } void draw() { // run the evolution of our objects populus.simulate(); // display our evolution information displayInfo(); if (populus.isFinished()) { noLoop(); } } void displayInfo() { // clear the background background(0); stroke(255); // display the current best fit DNA sequence String bestFit = populus.getBestFit(); textFont(font48, 48); text(bestFit, 10, 75); // display some statistics on our population textFont(font16, 16); text("total generations: " + populus.getGenerations(), 10, 240); text("average fitness: " + populus.getAverageFitness(), 220, 240); text("total population: " + populationSize, 10, 270); text("mutation rate: " + (int)(mutationRate * 100) + "%", 220, 270); }