xxxxxxxxxx
71
class Box{
constructor(radius,x,y){
this.x = x;
this.y = y;
this.rry = [];
this.radius = radius;
this.cl = parseInt(random(360));
}
verticesArray(){
for(let i=30; i<=360; i+=60){
let x = cos(i) * this.radius;
let y = sin(i) * this.radius*2;
this.rry.push(createVector(x,y));
}
}
display(){
rectMode(CORNER);
angleMode(DEGREES);
push();
translate(this.x,this.y);
rotate(180);//0 degrees looks like view from bottom, 180 top
this.verticesArray();
for(let i=0; i<this.rry.length; i+=2){
let p1 = this.rry[i];
let p2 = this.rry[i+1];
let p3 = i === 4 ? this.rry[0] : this.rry[i + 2];
let p4 = createVector(0,0);
if(i == 4){
//leftside
fill('hsb('+this.cl+',40%,30%)');
quad(p1.x,p1.y,p2.x,p2.y,p3.x,p3.y,p4.x,p4.y);
}else if( i == 0){
//topside
fill('hsb('+this.cl+',40%,30%)');
quad(p1.x,p1.y,p2.x,p2.y,p3.x,p3.y,p4.x,p4.y);
}else{
//rightside
fill('hsb('+this.cl+',70%,80%)');
quad(p1.x,p1.y,p2.x,p2.y,p3.x,p3.y,p4.x,p4.y);
}
}
pop();
}
}