วันอาทิตย์ที่ 23 พฤศจิกายน พ.ศ. 2557

Lab 5 - class House

void setup(){
  size(500,500);
  background(255);
  House h = new House(100,100,150,150);
  h.display();
}
class House{
  int x,y,w,h;
  Door door;
  Window left_window;
  Window right_window;
  Roof roof;
  House(int x,int y,int w,int h){
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
    this.door = new Door(this.x+((this.w*2)/5),this.y+(this.h/2),this.w/5,this.h/2);
    this.left_window = new Window(this.x+(this.w/7),this.y+(this.h/2),this.w/7,this.h/5);
    this.right_window = new Window(this.x+((this.w*5)/7),this.y+(this.h/2),this.w/7,this.h/5);
    this.roof = new Roof(this.x,this.y,this.w,this.h/2);
  }
  void display(){
    rect(this.x,this.y,this.w,this.h);
    this.door.display();
    this.left_window.display();
    this.right_window.display();
    this.roof.display();
  }
}
class Door{
  int x,y,w,h;
  Door(int x,int y,int w,int h){
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
  }
  void display(){
    rect(this.x,this.y,this.w,this.h);
  }
}
class Window{
  int x,y,w,h;
  Window(int x,int y,int w,int h){
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
  }
  void display(){
    rect(this.x,this.y,this.w,this.h);
    line(this.x+(this.w/2),this.y,this.x+(this.w/2),this.y+this.h);
    line(this.x,this.y+(this.h/2),this.x+this.w,this.y+(this.h/2));
  }
}
class Roof{
  int x,y,w,h;
  Roof(int x,int y,int w,int h){
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
  }
  void display(){
    triangle(this.x,this.y,this.x+(this.w/2),this.y-this.h,this.x+this.w,this.y);
  }
}