xxxxxxxxxx
153
class House{
constructor(clicked){
let s = 150; // length of first cube side
let h = 70; // height of triangle prism
let gh = 90; // garage height;
let gl = 130; // garage length;
let c = clicked
this.rot = 0;
this.lpoints = [];
this.lpoints.push(new LPoint(-s,-s/2,s/2,"A",c[0])) // a1
this.lpoints.push(new LPoint(-s/2,-s/2-h,s/2,"T",c[1])) // b5
this.lpoints.push(new LPoint(0,-s/2,s/2,"L",c[2])) // a2
this.lpoints.push(new LPoint(0,s/2-gh,s/2,"E",c[3])) // c1
this.lpoints.push(new LPoint(gl,s/2-gh,s/2,"A",c[4])) // c2
this.lpoints.push(new LPoint(gl,s/2,s/2,"S",c[5])) // c3
this.lpoints.push(new LPoint(0,s/2,s/2,"T",c[6])) // a3
this.lpoints.push(new LPoint(-s,s/2,s/2,"T",c[7])) // a4
this.lpoints.push(new LPoint(-s,-s/2,-s/2,"H",c[8])) // a5
this.lpoints.push(new LPoint(-s/2,-s/2-h,-s/2,"E",c[9])) // b6
this.lpoints.push(new LPoint(0,-s/2,-s/2,"Y",c[10])) // a6
this.lpoints.push(new LPoint(0,s/2-gh,-s/2,"T",c[11])) // c5
this.lpoints.push(new LPoint(gl,s/2-gh,-s/2,"R",c[12])) // c6
this.lpoints.push(new LPoint(gl,s/2,-s/2,"I",c[13])) // c7
this.lpoints.push(new LPoint(0,s/2,-s/2,"E",c[14])) // a7
this.lpoints.push(new LPoint(-s,s/2,-s/2,"D",c[15])) // a8
// two imaginary points
this.lpoints.push(new LPoint(-s/2,-s/2,s/2,"T",0)) // b5
this.lpoints.push(new LPoint(-s/2,-s/2,-s/2,"E",0)) // b6
// this.lpoints = [];
// this.lpoints.push(new LPoint(-s,-s/2,s/2,"A",c[0])) // a1
// this.lpoints.push(new LPoint(0,-s/2,s/2,"L",c[1])) // a2
// this.lpoints.push(new LPoint(0,s/2,s/2,"T",c[2])) // a3
// this.lpoints.push(new LPoint(-s,s/2,s/2,"T",c[3])) // a4
// this.lpoints.push(new LPoint(-s,-s/2,-s/2,"H",c[4])) // a5
// this.lpoints.push(new LPoint(0,-s/2,-s/2,"Y",c[5])) // a6
// this.lpoints.push(new LPoint(0,s/2,-s/2,"E",c[6])) // a7
// this.lpoints.push(new LPoint(-s,s/2,-s/2,"D",c[7])) // a8
// this.lpoints.push(new LPoint(-s/2,-s/2-h,s/2,"T",c[8])) // b5
// this.lpoints.push(new LPoint(-s/2,-s/2-h,-s/2,"E",c[9])) // b6
// this.lpoints.push(new LPoint(0,s/2-gh,s/2,"E",c[10])) // c1
// this.lpoints.push(new LPoint(gl,s/2-gh,s/2,"A",c[11])) // c2
// this.lpoints.push(new LPoint(gl,s/2,s/2,"S",c[12])) // c3
// this.lpoints.push(new LPoint(0,s/2-gh,-s/2,"T",c[13])) // c5
// this.lpoints.push(new LPoint(gl,s/2-gh,-s/2,"R",c[14])) // c6
// this.lpoints.push(new LPoint(gl,s/2,-s/2,"I",c[15])) // c7
console.log("house c " + c);
}
draw(){
push();
this.drawHouse();
this.drawPoints();
this.drawLetters();
pop();
}
drawLine(n1, n2){
beginShape();
vertex(this.lpoints[n1].pos.x,this.lpoints[n1].pos.y,this.lpoints[n1].pos.z);
vertex(this.lpoints[n2].pos.x,this.lpoints[n2].pos.y,this.lpoints[n2].pos.z);
endShape();
}
drawHouse(){
this.rot = millis()/10000;
rotateX(-0.2);
rotateY(this.rot)
stroke(0);
strokeWeight(1.5);
// HOUSE CUBE
// first face
this.drawLine(0,2);
this.drawLine(2,6);
this.drawLine(6,7);
this.drawLine(7,0);
//second face
this.drawLine(8,10);
this.drawLine(10,14);
this.drawLine(14,15);
this.drawLine(15,8);
// //links from first face to second
this.drawLine(0,8)
this.drawLine(2,10)
this.drawLine(6,14)
this.drawLine(7,15)
// // HOUSE ROOF
this.drawLine(0,1)
this.drawLine(1,2)
this.drawLine(8,9)
this.drawLine(9,10)
this.drawLine(1,9)
//DRAW GARAGE
//squares
this.drawLine(3,4)
this.drawLine(4,5)
this.drawLine(5,6)
this.drawLine(11,12)
this.drawLine(12,13)
this.drawLine(13,14)
// // draw link
this.drawLine(3,11)
this.drawLine(4,12)
this.drawLine(5,13)
}
drawPoints(){
for(let i = 0; i < this.lpoints.length -2; i++){
push();
translate(this.lpoints[i].pos.x,this.lpoints[i].pos.y,this.lpoints[i].pos.z)
if(this.lpoints[i].active){
stroke(255,30,0,100);
}
else{
stroke(0);
}
sphere(2);
pop();
}
}
drawLetters(){
for(let i = 0; i < this.lpoints.length -2; i++){
push();
translate(this.lpoints[i].pos.x,this.lpoints[i].pos.y,this.lpoints[i].pos.z)
if(this.lpoints[i].active){
fill(0);
}
else{
fill(200);
}
rotateY(-this.rot)
text(this.lpoints[i].letter, -5, -5);
pop();
}
}
}
class LPoint{
constructor(x,y,z,l,a,o=0){
this.pos = createVector(x,y,z);
this.letter = l;
this.active = a; // 0 if inactive
this.order = o;
}
}