You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

30 lines
901 B

class Tree{
constructor(x, w, h){
this.x = x;
this.width = w;
this.height = h;
let c = round(random(60, 100));
this.color = {r: c, g: round(random(170, 230)), b: c};
}
show(){
if (this.x + this.height * 0.375 > viewPort.x && this.x - this.height * 0.375 < viewPort.x + width){
let yArr = [];
for (let x = this.x - this.width / 2; x < this.x + this.width / 2; x++){
try{yArr.push(ground[round(x)].y);}
catch(e){}
}
let crownY = max(yArr) - this.height;
fill(80, 50, 40);
rect(this.x - this.width / 2, crownY, this.width, this.height);
fill(this.color.r, this.color.g, this.color.b);
ellipse(this.x, crownY, this.height / 2, this.height / 2);
for (let i = 0; i < TWO_PI; i += 1 / 4 * PI){
let x = this.x + this.height / 4 * sin(i);
let y = crownY + this.height / 4 * cos(i);
ellipse(x, y, this.height / 2, this.height / 2);
}
}
}
}