//Create your dream home
//Click and drag on the partitioning to model your personalized building
//Henry S. DeBey
//Project 4

Object[] myObjects;
Object[] myObjects2;
Object[] myObjects3;
Object[] myObjects4;
Object[] myObjects5;
int numObjects = 3;
int numObjects2 = 3;
int numObjects3 = 3;
int numObjects4 = 3;
int numObjects5 = 3;
PImage f;



void setup() {
  size(600,300);
  f = loadImage("forest.jpg");
  myObjects = new Object [numObjects];
  myObjects2 = new Object [numObjects2];
  myObjects3 = new Object [numObjects3];
  myObjects4 = new Object [numObjects4];
  myObjects5 = new Object [numObjects5];
  for(int i = 0; i<numObjects; i++) {
    myObjects[i] = new Object(10, i*10+10, 100, 8, 25);
    }
  for(int i = 0; i<numObjects2; i++) {
    myObjects2[i] = new Object(i*70+125, 10, 130, 50, 25);
    }
  for(int i = 0; i<numObjects3; i++) {
    myObjects3[i] = new Object(10, i*15+75, 70, 10, 25);  
    }
  for(int i = 0; i<numObjects4; i++) {
    myObjects4[i] = new Object(i*16+90, 75, 40, 70, 25);
    }
  for(int i = 0; i<numObjects5; i++) {
    myObjects5[i] = new Object(i*10+10, 150, 30, 70, 25);
    }
     
}

void draw() {
  background(255);
  image(f, 0, 0);
  //block.moveBy( 2, 2 );
  //block.display();
  for(int i=0; i<numObjects; i++) {
    myObjects[i].display();  
    myObjects2[i].display();
    myObjects3[i].display();  
    myObjects4[i].display();
    myObjects5[i].display();          
  }
}

void mousePressed() {
  for(int i=0; i<numObjects; i++) {
  if ( myObjects[i].contains(mouseX, mouseY) ) {
    myObjects[i].beingDragged = true;
    }   
  if ( myObjects2[i].contains(mouseX, mouseY) ) {
    myObjects2[i].beingDragged = true;
    }
  if ( myObjects3[i].contains(mouseX, mouseY) ) {
    myObjects3[i].beingDragged = true;
    }
  if ( myObjects4[i].contains(mouseX, mouseY) ) {
    myObjects4[i].beingDragged = true;
    }
  if ( myObjects5[i].contains(mouseX, mouseY) ) {
    myObjects5[i].beingDragged = true;
    }        
  }
}

void mouseReleased() {
  for(int i=0; i<numObjects; i++) {
    myObjects[i].beingDragged = false;
    myObjects2[i].beingDragged = false;
    myObjects3[i].beingDragged = false;
    myObjects4[i].beingDragged = false;
    myObjects5[i].beingDragged = false;
    }
}

void mouseDragged() {
  for(int i=0; i<numObjects; i++) {
  if ( myObjects[i].beingDragged ) {
    int diffX = mouseX - pmouseX;
    int diffY = mouseY - pmouseY;    
    myObjects[i].moveBy( diffX, diffY );
    } 
  if ( myObjects2[i].beingDragged ) {
    int diffX = mouseX - pmouseX;
    int diffY = mouseY - pmouseY;    
    myObjects2[i].moveBy( diffX, diffY );
    } 
  if ( myObjects3[i].beingDragged ) {
    int diffX = mouseX - pmouseX;
    int diffY = mouseY - pmouseY;    
    myObjects3[i].moveBy( diffX, diffY );
    } 
  if ( myObjects4[i].beingDragged ) {
    int diffX = mouseX - pmouseX;
    int diffY = mouseY - pmouseY;    
    myObjects4[i].moveBy( diffX, diffY );
    }
  if ( myObjects5[i].beingDragged ) {
    int diffX = mouseX - pmouseX;
    int diffY = mouseY - pmouseY;    
    myObjects5[i].moveBy( diffX, diffY );
    }     
  }
}

//-------------------------------------------

class Object {
  int x,y,w,h, d;
  boolean beingDragged;
  
  Object(int xpos, int ypos, int wid, int hei, int dep) {
    x = xpos;
    y = ypos;
    w = wid;
    h = hei;
    d = dep;
    beingDragged = false;
  }
  
  void display() {
    fill(255, 40);
    stroke(255);    
    rect(x,y,w,h);
    push();
    translate(x+w/2,y+h/2, -d/2);
    box(w,h,d);
    pop();   
    
  }
  
  void moveTo(int xpos, int ypos) {
    x = xpos;
    y = ypos;
  }
  
  void moveBy(int xmov, int ymov) {
    x += xmov;
    y += ymov;
  }
  
  boolean contains ( int xpos, int ypos ) {
    if ( xpos>x && xpos<x+w && ypos>y && ypos<y+h ) {
      return true;
    } else {
      return false;
    }
  }
}
Project 4: Context
Extend an idea you've explored previously in your life, but adapt it to the context of an interactive system which requires the viewer to engage with the material.