int x; //Attribute of class Door //x mean x position
int y; //y mean y position
int w; //w mean width
int hi; //hi mean height
Door (int x, int y, int w, int hi) { //Constructor of class Door
this.x = x;
this.y = y;
this.w = w;
this.hi = hi;
}
void display1() { //method of class Door
rect(this.x, this.y, this.w, this.hi);
}
}
//////////////////////////////////
class Window { //class of Window
int x; //Attribute of calss Window
int y;
int w;
int hi;
Window (int x, int y, int w, int hi) {
this.x = x; //constructor of Class Window
this.y = y;
this.w =w;
this.hi = hi;
}
void display2() { //method of class Window
rect (this.x, this.y, this.w, this.hi);
}
}
////////////////////////////////////
class House { //class of House
int x; //Attribute of class House
int y;
int w;
int hi;
Door door; //defined obj. of class Door in Class House
Window left_window;
Window right_window;
House (int x, int y, int w, int hi) { //constructer of class House
this.x =x;
this.y =y;
this.w =w;
this.hi =hi;
}
void setDoor (Door d) { //method of Class House that have parameter from Class Door
this.door = d;
}
void setWindowLeft (Window a) { //method of claa House that have parameter from Class Window
this.left_window = a;
}
void setWindowRight (Window b) {
this.right_window = b;
}
void display() {
rect(this.x, this.y, this.w, this.hi);
triangle(this.x, this.y, this.x+(this.w/2), this.y-(this.hi/2), (this.x)+(this.w), this.y);
this.door.display1(); //defined obj. for call method display in Class Door
this.left_window.display2();
this.right_window.display2();
}
}
void setup() {
size (500, 500);
background(0);
House h = new House(100, 150, 300, 250);
h.setDoor(new Door(200, 200, 100, 200));
h.setWindowLeft(new Window(125, 180, 50, 50));
h.setWindowRight(new Window (325, 180, 50, 50));
h.display();
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น