// debug switch boolean debug = false; boolean debugInactive = false; boolean debugTotal = false; boolean debugInput = false; // stage variables int maxX = 400; int maxY = 400; // line variables int reproductionRate = 255; int maxMovement = 10; int populationLimit = 255; int[] lineLocX = new int[populationLimit+1]; int[] lineLocY = new int[populationLimit+1]; boolean[] newlyBorn = new boolean[populationLimit+1]; boolean[] lineActive = new boolean[populationLimit+1]; color[] pixelColor = new color[256]; int maxLines = 1; int male, female; boolean empty; int decision; int colorR, colorG, colorB; int y; int move; void setup() { if (debug) { println("Program started.\n"); println("Population Limit Set @ "+populationLimit); println("Reproduction Rate Set @ "+reproductionRate); println("Maximum Pixel Movement Set @ "+maxMovement); println("INACTIVE line DEBUG Set @ "+debugInactive+"\n"); } for (int x=1; x<=populationLimit; x++) { lineLocX[x] = 0; lineLocY[x] = 0; newlyBorn[x] = false; lineActive[x] = false; pixelColor[x] = color(0,0,0); } lineLocX[1] = maxX / 2; lineLocY[1] = maxY / 2; lineActive[1] = true; pixelColor[1] = color(red(int(random(256)+1)), green(int(random(256)+1)), blue(int(random(256)+1))); size(maxX, maxY); framerate(30); smooth(); // noStroke(); background(255); // noLoop(); } void displayPoint(int x) { fill(pixelColor[x]); ellipse(lineLocX[x],lineLocY[x],10,10); // set(lineLocX[x],lineLocY[x],pixelColor[x]); } void draw() { if (debug) { print("\n"); } for (int x=1; x<=populationLimit; x++) { if ((lineActive[x]) && (!newlyBorn[x])) { if (debug) { print("Processing line #"+x+": ACTIVE "); } move = int(random(maxMovement))+1; decision = int(random(4)); if ((decision == 0) && (lineLocY[x] > 0)) { lineLocY[x] = lineLocY[x] - move; } /* UP */ if ((decision == 1) && (lineLocX[x] < maxX)) { lineLocX[x] = lineLocX[x] + move; } /* RIGHT */ if ((decision == 2) && (lineLocY[x] < maxY)) { lineLocY[x] = lineLocY[x] + move; } /* DOWN */ if ((decision == 3) && (lineLocX[x] > 1)) { lineLocX[x] = lineLocX[x] - move; } /* LEFT */ if (debug) { print("heading "); if (decision == 0) { print("NORTH "); } if (decision == 1) { print("EAST "); } if (decision == 2) { print("SOUTH "); } if (decision == 3) { print("WEST "); } print("on X:"+lineLocX[x]+",Y:"+lineLocY[x]+" "); } colorR = int(random(-4,4)); colorG = int(random(-4,4)); colorB = int(random(-4,4)); pixelColor[x] = pixelColor[x]+color(colorR,colorG,colorB); if (debug) { print("with color: "+int(red(pixelColor[x]))+","+int(green(pixelColor[x]))+","+int(blue(pixelColor[x]))+" "); } displayPoint(x); // if the point is at the edge, kill it. if ((lineLocX[x] <= 0) || (lineLocX[x] >= maxX) || (lineLocY[x] <= 0) || (lineLocY[x] >= maxY)) { lineActive[x] = false; if (debug) { print("THIS LINE HAS BEEN KILLED! ----- ----- ----- -----"); } maxLines--; } male = int(random(reproductionRate)); female = int(random(reproductionRate)); if ((male != female) && (lineActive[x]) && (debug)) { print("(male disagreed with female, "+male+"!="+female+") "); } if ((male == female) && (lineActive[x]) && (maxLines == populationLimit) && (debug)) { print("PROGRAM HAS REACHED POPULATION CAP SO NO CHILD WAS CREATED (male agrees with female, "+male+"="+female+") ===== ===== ===== ====="); } if ((male == female) && (lineActive[x]) && (maxLines < populationLimit)) { empty = false; while (!empty) { y = int(random(populationLimit))+1; if (!lineActive[y]) { if (debug) { print("CHILD CREATED! CHILD'S NAME IS ("+y+") (male agrees with female, "+male+"="+female+") +++++ +++++ +++++ +++++"); } lineActive[y] = true; // tell program that this line is active empty = true; // terminate loop lineLocY[y] = lineLocY[x]; // pass parent's Y coordinates to the child lineLocX[y] = lineLocX[x]; // pass parent's X coordinates to the child pixelColor[y] = pixelColor[x]; // pass parent's colors to the child newlyBorn[y] = true; // declare that the child is not ready for locomotion. // a minimum of one turn passes until the child moves. maxLines++; // increment maxLines } } } if (debug) { print("\n"); } } else if ((lineActive[x]) && (newlyBorn[x])) { if (debug) { displayPoint(x); print("Processing line #"+x+": ACTIVE but is still a NEW BORN. Will move next turn.\n"); } newlyBorn[x] = false; } else if ((!lineActive[x]) && (debugInactive)) { print("INACTIVE\n"); } delay(1); } if (debugTotal) { println("Program has now: "+maxLines+" children."); } if (maxLines <= 0) { println("Terminate program execution. Population has reached 0."); } } //void mousePressed() { // loop(); //} // void mouseReleased() { // if (debugInput) { // println("Mouse released... Halting loop."); // } // noLoop(); //}