• fullscreen
  • Being.pde
  • WorldManager.pde
  • procreate.pde
  • class Being {
      float redVal;
      float greenVal;
      float blueVal;
      float alphaVal;
      float xloc;
      float yloc;
      int age;
      boolean isPregnant;
      boolean isAlive;
      int progeny;
      int gestation;
      float speed = 2;
      //boolean isIncest;
      //int inbreeding;
    
      Being() {
        alphaVal = 255;
        redVal = 255;
        greenVal = 40;
        blueVal = 100;
        xloc = random(width);
        yloc = random(height);
        gestation = 0;
        isPregnant = false;
        isAlive = true;
        progeny = 0;
        age = 200;
      }
    
      Being(float xloc_, float yloc_/*, color b1Color, color b2Color*/) {
        //initcolor;
        redVal = 255;
        greenVal = 40;
        blueVal = 100;
        alphaVal = 255;
        gestation = 0;
        isPregnant = false;
        isAlive = true;
        progeny = 0;
        xloc = xloc_;
        yloc = yloc_;
        age = 0;
      }
    
      void wander(float speed_) {
        xloc += random(-speed_,speed_);
        yloc += random(-speed_,speed_);
      }
    
      void rest() {
        isPregnant = true;
      }
    
      void incrementValues() {
        age++;
        redVal -= 20;
        if(alphaVal > 30) {
          alphaVal--;
        }
      }
    
      void checkAge() {
        if(age > maxAge * 5) {
          isAlive = false;
        }
      }
    
      void drawMe() {
        noStroke();
        fill(redVal, greenVal, blueVal, alphaVal);
        ellipse(xloc, yloc, 5, 5);
        wander(speed);
      }
      
      //upon birth, leave home
      void migrate() {
        xloc += random(-10, 10);
        yloc += random(-10, 10);
        }
    }
    
    
    class WorldManager {
    
      //instantiate objects
      void spawn(int num) {
        for (int i = 0; i < num; i++) {
          humans.add(new Being());
        }
      }
      
      //multiply at location
      void procreate(Being being1, Being being2) {
        Being b1 = being1;
        Being b2 = being2;
        Being b3 = new Being(b1.xloc + random(-width/3, width/3), b1.yloc + random(-height/3, height/3));
        //b3.migrate();
        humans.add(b3);
        b1.isPregnant = true;
        //b2.isPregnant = true;
        b1.progeny++;
        b2.progeny++;
    
        /*if(isIncest) {
         being3.inbreeding++;
         }*/
      }
      
      //look for mate
      void scan(Being h_) {
        if(h_.age < consentAge*10 || h_.progeny > maxChildren) {
          // do nothing 
        }
        else if(h_.isPregnant) {
    
          if(h_.gestation < gestationPeriod * 10) { 
            h_.gestation++;
          }
          else {
            h_.isPregnant = false;
          }
        }
        else {
          for(int i=0; i<numHumans; i++) {
            for(int j=0; j<numHumans; j++) {
              if (i != j) {
                Being b1 = (Being) humans.get(i);
                Being b2 = (Being) humans.get(j);
                //check proximity 
                if(dist(b1.xloc, b1.yloc, b2.xloc, b2.yloc) < territory) {
                  if(random(1) > chanceToScore) {
                    procreate(b1, b2);
                  }  
                }
              }
            }
          }
        }
      }
    }
    
    //Post Apocalypse Scenario by Cameron Cundiff
    
    int consentAge = 18; //can vary
    int maxAge = 100; //chance to die before this value. increment based on population size, size life expectancy should increase with the advent of technology associated with developed populations
    float gestationPeriod = .75; //fixed to 9 months, with a 2 week buffer
    float territory = 15;
    int maxChildren = 2;//inverse to population size
    int maxHumans = 1000;//for debugging
    float chanceToScore = .99;//inverse to population size. Fewer options equals better chance to score!
    
    
    //too much inbreeding causes a zombie outbreak
    /*
      void geneScreen(Being testSubject) {
     if(testSubject.inbreeding > 3) {
     outbreak();
     }
     }
     
     
     void outBreak() {
     //zomg zombies!
     }
     */
    
    
    int numHumans = 15;
    ArrayList humans = new ArrayList();
    WorldManager bigBrother = new WorldManager();
    
    void setup() {
      size(400,400); 
      //output = createWriter("positionsUnderage.txt");
      bigBrother.spawn(numHumans);
    }
    
    void draw() {
      background(255);
      smooth();
      
      //chanceToScore = 1 - float(humans.size())/maxHumans;
      
      for(int i = humans.size()-1; i >= 0; i--) { 
        Being h = (Being) humans.get(i);
        if (!h.isAlive) {
          humans.remove(i); 
        }
      }
      
      for(int i = humans.size()-1; i >= 0; i--) { 
        Being h = (Being) humans.get(i);
        h.drawMe();
        bigBrother.scan(h);
        h.incrementValues();
        h.checkAge();
      }
      
      //output.println(humans.size());
      println(humans.size());
      
    }
    
    /*
    void keyPressed() {
      output.flush();
      output.close();
      exit();
    }
    */
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Cameron Cundiff

    Procreation

    Add to Faves Me Likey@! 1
    You must login/register to add this sketch to your favorites.

    Revision of a post apocalypse scenario in which humans either go extinct or repopulate the earth after a zombie outbreak.

    You need to login/register to comment.