Object Oriented Programming Art

For this week’s assignment, we were supposed to create something with OOP. I wanted to create some sort of meditative art work (e.g. snow/rain falling) but along the process of learning how to form a “class” and other programming, I made this. I kind of ended up liking this more (despite its lack of clear purpose).

Drop [] dropCollection = new Drop [70];

 
void setup() {
 size(400, 400);
 smooth();
 
 for ( int n = 0; n < 70; n++) {
 dropCollection[n] = new Drop (random(0,width), random(0,height));
  
}

 }
 
 
void draw() {
   background(187, 178, 255);
   
   for (int n = 0; n < 70; n++) {
   dropCollection[n].run();
   
   
 }
 
}
class Drop{

  float x = 0;
  float y = 0;
  float speedX = 2;
  float speedY = 5;
  float r;
  
  Drop(float _x, float _y) {
    x = _x;
    y = _y;
    r = 8;
    
  }
  
  void run(){
    display();
    move();
    bounce();
    gravity();
    
  }
  
  void gravity(){
  speedY *= 0.2;
  
  }
    
  void bounce() {
    if(x > width) {
      speedX = speedX * -1;  
    }
    if(x < 0) {
      speedX = speedX * -1;  
    }
     if(y > width) {
      speedY = speedY * -1;  
    }
        if(y < 0) {
      speedY = speedY * -1;  
    }
    
  }
  
 void move() {
    
  x += speedX;
  y += speedY;
  
  }
  
    void display() { 
    
    fill( random(255), random(255), random(255), random(255)); 
    noStroke();

    for (int i = 2; i < r; i++ ) {
    ellipse(x, y + i*4, i*2, i*2);
   

  }
  }
}

 

Leave a Reply