import noc.*; //World variables int maxThings = 10; int maxFood = 150; float foodMass = 0.5; float minMass_ = 2; float maxMass_ = 5; float dMin = 5; float repForce = 0.001; float mutationRate = 0.01; // Initial DNA float hunger_ = 10000; //10000 float hornyFactor_ = 100; //50 float foodInc_ = 0.001; float deathRate_ = 0.005; float max_vel_ = 3; float foodDist = 10; //Perlin noise variables float xoff = 0.1; float yoff = 0.1; float xincrement = 0.05; float yincrement = 0.01; float px; float py; PFont font; int maxAttractors = 2; int trailAmount = 25; int aNum = 4; int pNum = 0; int aMouse; boolean showVectors = false; boolean started = false; boolean show = true; ThingParticleSystem tPs; FoodParticleSystem fPs; int numDead = 0; int foodTimer = 0; void setup() { font = loadFont("ACaslonPro-Bold-48.vlw"); textFont(font, 12); size(800,400); //size(screen.width,screen.height); smooth(); colorMode(RGB,255,255,255,100); tPs = new ThingParticleSystem(); fPs = new FoodParticleSystem(); frameRate(30); } void draw() { fill(0,trailAmount); rect(0,0,width,height); tPs.run(); fPs.run(); if (foodTimer%200 == 0){ fPs.addParticle(1); } foodTimer++; if (tPs.total() <= 1){ reset(); } if (tPs.total() > 100){ tPs.delParticle(0); } text("Press M or N for more or less things. B or V for more or less food. R to RESET", 10,height-10); } void mousePressed() { } void mouseReleased() { //reset(); } void keyPressed() { // showVectors = !showVectors; if (key == 'r' || key == 'R'){ reset(); } else if(key == 's' || key == 'S'){ showVectors = !showVectors; } else if (key == 'm'|| key == 'M'){ tPs.addParticle(); } else if (key == 'b'|| key == 'B'){ fPs.addParticle(1); } else if (key == 'n'|| key == 'N'){ tPs.delParticle(0); } else if (key == 'v'|| key == 'V'){ fPs.remParticle(0); } else if (pNum < aNum){ pNum = aNum; aNum++; if (aNum == maxAttractors){ aNum--; pNum = maxAttractors; } } else{ aNum--; if(aNum == 0 ){ pNum = 0; aNum++; } } } // Renders a vector object 'v' as an arrow and a location 'loc' void drawVector(Vector3D v, Vector3D loc, float scayl) { if (v.magnitude() > 0.0) { pushMatrix(); float arrowsize = 4; // Translate to location to render vector translate(loc.x,loc.y); stroke(255); // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate rotate(v.heading2D()); // Calculate length of vector & scale it to be bigger or smaller if necessary float len = v.magnitude()*scayl; // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction) line(0,0,len,0); line(len,0,len-arrowsize,+arrowsize/2); line(len,0,len-arrowsize,-arrowsize/2); popMatrix(); } } void reset(){ started = false; aNum = 1; pNum = 0; for (int i = 0; i < tPs.total(); i++){ tPs.delAllParticles(i); } for (int i = 0; i < fPs.total(); i++){ fPs.delParticle(i); } tPs = new ThingParticleSystem(); fPs = new FoodParticleSystem(); }