Survival of the fittest

***current works in progress.

Inspired by evolution, my object oriented programming sketch is centered around different colored circles that represent different species, emerging at random and when clicked on duplicate exponentially. However, one circle from each species “dies off ” (removed) at random. Once one full row of circles fill up the top of the window, they “die off” by having the whole row disappear , this represents the death of older generations in rise of newer ones, and the cycle continues.

// still work in progress
Bubble b; 
void setup() {
  size(640, 360);
  b = new Bubble(64); // b is a new instance a bubble object, Bubble() is a constructor.
};
void draw() {
  background(255);
    //backdrop();
  b.top();
  b.display();
  b.ascend();//dot syntax, calling a function on that object.

};

//__________________
class Bubble {
  float x;
  float y;
  float diameter;

  Bubble(float tempD) { 
    x=width/2;
    y=height/2;
    diameter=tempD;
  };

  void display() {
    stroke(0);
    fill(127);
    ellipse(x, y, diameter, diameter);
  };

  void top() {
    if (y<diameter/2) {
      y=diameter/2;
    };
  };
  void ascend() {
    y--;
    x=x+random(-2, 2);
  };
};

______________________________________

Updated version: Box Game 🙂

float x = width/6;
float y = height/6;
// Click within the image to change 
// the value of the rectangle
void setup() {
  background(#FFA500);
  size(600, 600);
  ellipseMode(CENTER);
};
void draw() {
   keyPressed() ;

  if (mousePressed == true) {
    //background(100);
    fill(0);
    x+=1;

    //} else {
    //  fill(255);
  }
  //rect(25, 25, 50, 50);
  rect(x, y, 100, 100); //rect(x+random(-1, 1), y, 100, 100);
  if (keyPressed == true) {
    //background(100);
    fill(255);
    y+=1;
  };

};



  void keyPressed() {
    if(key == 's'){ 
    rect(x+100, y+100, 100, 100);
    
  };
   if(key == 's'){ 
    rect(x+200, y+200, 100, 100);
    
  };

  };

OOP Version: I lost some of the serendipity in the OOP version of this box interaction, versus in the one above. This assignment was harder the last but taught me a lot in code organization.

Box b;
Box b2;
void setup() {
  size(600, 600);
  b= new Box();
  b2= new Box();//change color and xy position.
};
void draw() {
  background(#FFA500);
  b.display();
  b.moveRight();
  b.moveLeft();
  b.leftWall();
  b.move();
  b.duplicate();
  //b.mirror();
  //b.addNewObjToArray();
  //b.exponentialGrowth();
  //b.rightWall():
  //b.bounceEdge();
  //b.bottom
  //b.top
}
//_____________
class Box {
  float x = width/2;
  float y = height/2;
  float xpos = random(100, 100);
  float ypos =random(200, 200);

  float xspeed=5;


  void  display() {

    rect(x, y, 100, 100);
    rectMode(CORNER);
  };
  void moveRight() {
    if (keyPressed == true) {
      fill(255);
      x+=1;
    };
  };
  void moveLeft() {
    if (keyPressed == false) {
      fill(255);

      x-=1;
    };
  };
  void leftWall() { //will rest at the edge
    if (x>width||x<0) {
      x=x*-0.1;
    };
  };
  //void rightWall() {
  //    if (y>width||x<0) {
  //    y=y*0.1;
  //  };
  void move() {
    if (keyPressed == true) {
      //background(100);
      fill(255);
      y+=1;
    };
  }
  void duplicate() {

    if (key == 's') { 
      rect(x+100, y+100, 100, 100);
    };
    if (key == 's') {
    };
  };
 
}

 

 

Psychedelic Geometry :)

float angle;
float grid= 400;
float i=0; 
void setup() {
  size(1080, 900,P3D);
};

void draw() {
 
  for(int x=0;x<=width;x+=grid){
    for(int y=0;y<=height;y+=grid){
  translate(mouseX,mouseY);
rotateX(radians(angle));
rotateY(radians(angle));
i=0; 
  while(i<width){
    i=i+20;
  beginShape();
vertex(i+100,100);
vertex(i+175,50);
vertex(i+250,100);
vertex(i+250,200);
vertex(i+175,250);
vertex(i+100,200);
vertex(i+100,100);
vertex(i+100,200);

endShape();
  };
  
  };
  };
//rotateX(radians(angle));
angle+=1; //does a full rotation
};

For this assignment,

I went through A LOT of experimentation,

at first, I wanted to recreate this pattern:

I almost got there:

Then, I didn’t really know what to do with it in terms of animation….

I  discovered the built in P3D  and started different experiments, but  I didn’t know how to integrate more effects while using the While loop, so I experimented further and created the animation at the top of the post.

The inspiration of this post for me was to experiment as much as possible, since it’s been helping me understand the mechanics of the code. And to save different blocks of code on GitHub if I find something interesting I could integrate in a different art piece later.

Alia’s portrait

Unintentionally turning myself into Mrs.Potato Head….

void setup() {
  size (640, 480);
};

void draw() {
  hair();
  drawHead(); 
  drawLeftEye();
  drawRightEye();
  drawLips();

  leftNostril();
  rightNostril();
  noseTip();
  bangs();

  //255,192,203 is pink
};

void drawLeftEye() {

  fill(255, 255, 255);
  int x1=56;
  int y1=46;
  ellipse(x1+200, y1+120, 105, 55); //eyewhite
  fill(160, 82, 45); //iris color
  ellipse(x1+200, y1+120, 55, 55);
  fill(0, 0, 0);
  ellipse(x1+200, y1+120, 20, 20);
};

void drawRightEye() {
  int x1= 200;
  int y1=  46;
  fill(255, 255, 255);
  ellipse(x1+180, y1+120, 105, 55); //eyewhite
  fill(160, 82, 45); //iris color
  ellipse(x1+180, y1+120, 55, 55);
  fill(0, 0, 0);
  ellipse(x1+180, y1+120, 20, 20);
};

void drawHead() {
  int x1= 640;
  int y1= 480;
  fill(255, 239, 213);
  ellipse(x1/2, y1/2, 300, 400);
};


void drawLips() {

  fill(255, 192, 203);
  noStroke();
  int a = 30;
  int b =75;
  int c =100;
  int d =20;
  int e = 150;
  int f= 75;
  int g= 270;
  int h= 200;
  triangle(a+165, b+250, c+165, d+250, e+165, f+250);
  triangle(e+165, f+250, h+165, d+250, g+165, f+250);
  triangle(a+165, b+250, e+165, e+250, g+165, f+250);
  stroke(0, 0, 0);
  line(30+165, 75+250, 270+165, 75+250);
};
void leftNostril() {
  fill(255, 239, 213);
  int a= 640/2;
  int b= 480/2;
  ellipse(a-30, b, 40, 50);
};

void rightNostril() {
  fill(255, 239, 213);
  int a= 640/2;
  int b= 480/2;
  ellipse(a+20, b, 40, 50);
};
void noseTip() {
  fill(255, 239, 213);
  int a= 50;
  int b= 50 ;
  int c= 75;
  int d=100;
  int e=100;
  int f= 100;
  int g= 125;
  int h= 50;

  quad(a+230, b+150, c+230, d+150, e+230, f+150, g+230, h+150);
};

void bangs() {

  fill(78, 53, 36);
  int x1= 100;
  int y1= 200;
  int x2= 200;
  int y2= 200;
  int height= 210;
  int width= 210;
  arc(320, 110, height, width, 6*PI/6, 12*PI/6);
};

void hair() {

  fill(78, 53, 36);
  int x1= 640;
  int y1= 480;
  ellipse(x1/2, y1/2, 400, 500);
  //noStroke();
  rect(x1/2-200, y1/2, 400, 500);
};