class   "Trap_3nan"  in p5.js                         terug naar de inleiding

 zoe ook de class "Trap_3nan in processing

 

class Trap_3nan extends Vormen { 
   constructor(n, d, x, y, hoek, c) { 
     super(x,y,hoek); 
     this.x  = x; this.y = y;  this.hoek = hoek; 
     this.n  = n; this.d = d;  this.c = c; 
 } 
 display() { 
 fill(this.c); 
 push(); 
 translate(this.x, this.y); 
 rotate(radians(this.hoek)); 
 beginShape(); 
 if (this.d == 0) {vertex(-1.5*this.n, this.n/2); vertex(-this.n/2, -this.n/2); vertex(this.n/2, -this.n/2); vertex(1.5*this.n, this.n/2);} 
 if (this.d == 1) {vertex(0, 0); vertex(this.n, -this.n); vertex(2*this.n, -this.n); vertex(3*this.n, 0);} 
 if (this.d == 2) {vertex(-this.n/2, this.n/2);vertex(this.n/2, -this.n/2); vertex(1.5*this.n, -this.n/2); vertex(2.5*this.n, this.n/2);} 
 if (this.d == 3) {vertex(-this.n, this.n); vertex(0, 0); vertex(this.n, 0); vertex(2*this.n, this.n);} 
 if (this.d == 4) {vertex(-1.5*this.n, this.n); vertex(-this.n/2, 0); vertex(this.n/2, 0); vertex(1.5*this.n, this.n);} 
 if (this.d == 5) {vertex(-2*this.n, this.n); vertex(-this.n, 0); vertex(0, 0); vertex(this.n, this.n);} 
 if (this.d == 6) {vertex(-2.5*this.n, this.n/2); vertex(-1.5*this.n, -this.n/2); vertex(-this.n/2, -this.n/2);vertex(this.n/2, this.n/2);} 
 if (this.d == 7) {vertex(-3*this.n, 0); vertex(-2*this.n, -this.n); vertex(-this.n, -this.n); vertex(0, 0);} 
 if (this.d == 8) {vertex(-1.5*this.n, 0); vertex(-this.n/2, -this.n); vertex(this.n/2, -this.n); vertex(1.5*this.n, 0);} 
 endShape(CLOSE); 
 pop(); 
  }
}
 

class "Vlieger"

 zie ook de class  "Vlieger" in processing

constructor argumenten:

 1) n = lengte korte diagonaal, 2) h1 = lengte top naar korte diagonaal, 3) h2 = lengte punt naar korte diagonaal
 4) d = draaipunt, 5) x positie, 6) y positie, 7) hoek, 8) kleur

 
 
class Vlieger extends Vormen { 
//          1  2   3   4  5  6  7     8 
constructor(n, h1, h2, d, x, y, hoek, c) { 
    super(x, y, hoek) 
    this.x  = x; this.y  = y;  this.hoek = hoek; 
    this.n  = n; this.h1 = h1; this.h2 = h2; 
    this.d = d; this.c = c; 
 
  } 
 
  display() { 
    push(); 
    fill(this.c); 
    translate(this.x, this.y); 
    rotate(radians(this.hoek)); 
    beginShape(); 
    if (this.d == 0) {vertex(0, this.h2);          vertex(-this.n/2, 0);         vertex(0, -this.h1);                  vertex(this.n/2, 0);} 
    if (this.d == 1) {vertex(0, 0);                vertex(-this.n/2, -this.h2);  vertex(0, -(this.h1+this.h2));        vertex(this.n/2, -this.h2);} 
    if (this.d == 2) {vertex(this.n/4, this.h2/2); vertex(-this.n/4, -this.h2/2);vertex(this.n/4, -(this.h2/2+this.h1));vertex(3*this.n/4, -this.h2/2);} 
    if (this.d == 3) {vertex(this.n/2, this.h2);   vertex(0, 0);                 vertex(this.n/2, -this.h1);            vertex(this.n, 0);} 
    if (this.d == 4) {vertex(this.n/4, (this.h2+this.h1/2));vertex(-this.n/4, this.h1/2);vertex(this.n/4, -this.h1/2);  vertex(3*this.n/4, this.h1/2);} 
    if (this.d == 5) {vertex(0, this.h1+this.h2);          vertex(-this.n/2, this.h1);     vertex(0, 0);                vertex(this.n/2, this.h1);} 
    if (this.d == 6) {vertex(-this.n/4, (this.h1/2+this.h2));vertex(-3*this.n/4, this.h1/2); vertex(-this.n/4, -this.h1/2);vertex(this.n/4, this.h1/2);} 
    if (this.d == 7) {vertex(-this.n/2, this.h2);            vertex(-this.n, 0);             vertex(-this.n/2, -this.h1);  vertex(0, 0);} 
    if (this.d == 8) {vertex(-this.n/4, this.h2/2);vertex(-3*this.n/4, -this.h2/2);vertex(-this.n/4, -(this.h2/2+this.h1));vertex(this.n/4, -this.h2/2);} 
    endShape(CLOSE); 
    pop(); 
  } 
}