• fullscreen
  • procreate.pde
  • procreate05.pde
  • class Being {
      float xloc;
      float yloc;
      int age;
      float gestation;
      float territory;
      boolean isPregnant;
      int progeny;
      //boolean isIncest;
      //int inbreeding;
    
      Being() {
        xloc = random(width);
        yloc = random(height);
        age = 1800;
        gestation = 0;
        territory = 20;
        isPregnant = false;
        progeny = 0;
      }
    
      void wander() {
        xloc += random(-3, 3);
        yloc += random(-3, 3);
      }
    
      void rest() {
        isPregnant = true;
      }
    
      void drawMe() {
        noStroke();
        fill(0);
        ellipse(xloc, yloc, 2, 2);
      }
    
    }
    
    void procreate(Being being1, Being being2) {
      //move towards one another
      //new being
      Being being3 = new Being(); //how do I add this to the array human[]?
      human = (Being[]) append(human, being3);
      being3.xloc = being2.xloc;
      being3.yloc = being2.yloc;
      being3.age = 0;
      being2.isPregnant = true;
      being2.progeny++;
      /*if(isIncest) {
       being3.inbreeding++;
       }*/
    }
    
    void scan() {
      for(int i=0; i<numHumans; i++) {
        for(int j=0; j<numHumans; j++) {
         if (i != j) {
            if(dist(human[i].xloc, human[i].yloc, human[j].xloc, human[j].yloc) < human[i].territory) {
              procreate(human[i], human[j]);
            }
          }
        }
      }
    }
    
    //too much inbreeding causes a zombie outbreak
    /*
    void geneScreen(Being testSubject) {
     if(testSubject.inbreeding > 3) {
     outbreak();
     }
     }
     
     
     void outBreak() {
     //zomg zombies!
     }
     */
    
    
    int numHumans = 15;
    Being[] human = new Being[numHumans];
    
    void setup() {
      size(400,400); 
      for(int i=0; i < human.length; i++) {  
        human[i] = new Being();
        //human[i].xloc = random(0, width);
        //human[i].yloc = random(0, height);
      }
    }
    
    void draw() {
      background(255);
      for(int i = 0; i < human.length; i++) { 
        human[i].drawMe();
        human[i].wander();
        //prevents pop explosion crash
        if(human[i].age > 4000) {
          //particle dies
        }
        if(human[i].age < 1800 || human[i].progeny > 5) {
          // do nothing 
        }
        else if(human[i].isPregnant) {
          if(human[i].gestation < 900) { 
            human[i].gestation++;
          }
          else {
            human[i].isPregnant = false;
          }
        }
        else {
          scan();
          //geneScreen(human[i]);
        }
        human[i].age++;
      }
    
      //noLoop();
    }
    
    //check fertility
    //offspring
    //rest
    
    int consentAge = 100;
    int maxAge = 500;
    int gestationPeriod = 100;
    float territory = 15;
    int maxChildren = 2;
    
    class Being {
      float redVal;
      float greenVal;
      float blueVal;
      float alphaVal;
      float xloc;
      float yloc;
      int age;
      boolean isPregnant;
      boolean isAlive;
      int progeny;
      int gestation;
      //boolean isIncest;
      //int inbreeding;
    
      Being() {
        redVal = 255;
        greenVal = 40;
        blueVal = 100;
        alphaVal = 255;
        xloc = random(width);
        yloc = random(height);
        gestation = 0;
        isPregnant = false;
        isAlive = true;
        progeny = 0;
        age = 200;
      }
    
      Being(float xloc_, float yloc_) {
        redVal = 255;
        greenVal = 40;
        blueVal = 100;
        alphaVal = 255;
        gestation = 0;
        isPregnant = false;
        isAlive = true;
        progeny = 0;
        xloc = xloc_;
        yloc = yloc_;
        age = 0;
      }
    
      void wander() {
        xloc += random(-3, 3);
        yloc += random(-3, 3);
      }
    
      void rest() {
        isPregnant = true;
      }
    
      void incrementValues() {
        age++;
        redVal -= 20;
        if(alphaVal > 30) {
          alphaVal--;
        }
      }
    
      void checkAge() {
        if(age > maxAge) {
          isAlive = false;
        }
      }
    
      void drawMe() {
        noStroke();
        fill(redVal, greenVal, blueVal, alphaVal);
        ellipse(xloc, yloc, 5, 5);
      }
    
    }
    
    void procreate(Being being1, Being being2) {
      Being b1 = being1;
      Being b2 = being2;
      Being b3 = new Being(b1.xloc, b1.yloc);
      humans.add(b3);
      b1.isPregnant = true;
      //b2.isPregnant = true;
      b1.progeny++;
      b2.progeny++;
    
      /*if(isIncest) {
       being3.inbreeding++;
       }*/
    }
    
    void scan(Being h_) {
      if(h_.age < consentAge || h_.progeny > maxChildren) {
        // do nothing 
      }
      else if(h_.isPregnant) {
        
        if(h_.gestation < gestationPeriod) { 
          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);
    
              if(dist(b1.xloc, b1.yloc, b2.xloc, b2.yloc) < territory) {
                procreate(b1, b2);
              }
            }
          }
        }
      }
    }
    
    //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();
    
    void setup() {
      size(400,400); 
      for (int i = 0; i < numHumans; i++) {
        humans.add(new Being());
      }
    }
    
    void draw() {
      background(255);
      smooth();
    
      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();
        h.wander();
        scan(h);
        h.incrementValues();
        h.checkAge();
      }
    
    }
    
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Cameron Cundiff

    Post Apocolypse v2

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

    New Version, there's a problem with exponential growth, going to have to enforce population control :P
    A post apocalypse scenario, in which humans repopulate the earth. Inspired by the zombie infection app (Carl Sverre).

    we (with my sister) were looking at your code and we loved the naming convention:
    isPregnant, isBreeding, //check fertility, offspring, rest...
    Very Cool!
    Cameron Cundiff
    30 Sep 2008
    I'm glad! I actually censored it a bit, it was a little more risqué before ;)
    You need to login/register to comment.