class Bird{ constructor(x){ this.x = x; this.y = random(height * 0.05, height * 0.3); this.v = random([true, false]) ? random(3, 5) : random(-3, -5); this.length = random(50, 100); } move(){ this.x += this.v; if (this.x - this.length / 2 > worldWidth) this.x = -this.length / 2; if (this.x + this.length / 2 < 0) this.x = worldWidth + this.length / 2; } show(){ let wing = sin(0.02 * PI * this.x); if (this.x + this.length / 2 > viewPort.x && this.x - this.length / 2 < viewPort.x + width){ fill(0); beginShape(); vertex(this.x - this.length / 2, this.y); vertex(this.x - this.length * 0.4, this.y - this.length * 0.1); vertex(this.x + this.length * 0.15, this.y - this.length * 0.1); vertex(this.x + this.length * 0.15, this.y - this.length * 0.1 - this.length * 0.4 * wing); vertex(this.x + this.length * 0.1, this.y - this.length * 0.1 - this.length * 0.5 * wing); vertex(this.x + this.length * 0.05, this.y - this.length * 0.1 - this.length * 0.4 * wing); vertex(this.x, this.y - this.length * 0.1 - this.length * 0.5 * wing); vertex(this.x - this.length * 0.05, this.y - this.length * 0.1 - this.length * 0.4 * wing); vertex(this.x - this.length * 0.1, this.y - this.length * 0.1 - this.length * 0.5 * wing); vertex(this.x - this.length * 0.15, this.y - this.length * 0.1 - this.length * 0.4 * wing); vertex(this.x - this.length * 0.15, this.y - this.length * 0.1); vertex(this.x + this.length * 0.4, this.y - this.length * 0.1); vertex(this.x + this.length / 2, this.y); vertex(this.x + this.length * 0.4, this.y + this.length * 0.1); vertex(this.x - this.length * 0.4, this.y + this.length * 0.1); endShape(); fill(255); ellipse(this.x + ((this.v > 0) ? 1 : -1) * this.length * 0.4, this.y - this.length * 0.025, this.length * 0.05); } } }