Classes "Rechthoek" en "Ellips" in p5.js
zie ook de class "Rechthoek" in processing
class "Rechthoek" Deze class heeft als extra argumenten in de constructor: sw = lijndikte , strokeWeight() en sc = lijnkleur, stroke()
//argumenten van de constructor
//1) breedte, 2) hoogte, 3) draaipunt, 4) x positie, 5) y positie,
//6) hoek 7) vormkleur, 8) lijndikte, 9) lijnkleur
class Rechthoek extends Vormen {
// 1 2 3 4 5 6 7 8 9
constructor(n, h1, d, x, y, hoek, c, sw, sc) {
super(x, y, hoek);
this.x = x; this.y = y; this.hoek = hoek;
this.n = n; this.h1 = h1; this.d = d;
this.c = c; this.sw = sw; this.sc = sc;
}
display() {
fill(this.c);
let d = this.d; let n = this.n; let h1 = this.h1;
strokeWeight(this.sw);
stroke(this.sc);
push();
translate(this.x,this.y);
rotate(radians(this.hoek));
beginShape();
if (d == 1) {vertex(0, 0); vertex(0, -h1); vertex(n, -h1); vertex(n, 0); }
if (d == 2) {vertex(0, h1/2); vertex(0, -h1/2); vertex(n, -h1/2);vertex(n, h1/2);}
if (d == 3) {vertex(0, h1); vertex(0, 0); vertex(n, 0); vertex(n, h1); }
if (d == 4) {vertex(-n/2, h1);vertex(-n/2, 0); vertex(n/2, 0); vertex(n/2, h1);}
if (d == 5) {vertex(-n, h1); vertex(-n, 0); vertex(0, 0); vertex(0, h1);}
if (d == 6) {vertex(-n, h1/2);vertex(-n, -h1/2);vertex(0, -h1/2);vertex(0, h1/2);}
if (d == 7) {vertex(-n, 0); vertex(-n, -h1); vertex(0, -h1); vertex(0, 0);}
if (d == 8) {vertex(-n/2, 0); vertex(-n/2, -h1);vertex(n/2, -h1);vertex(n/2, 0);}
if (d == 0) {vertex(-n/2, h1/2);vertex(-n/2, -h1/2);vertex(n/2, -h1/2);vertex(n/2, h1/2);}
endShape(CLOSE);
pop();
}
}

Class "Ellips" Deze class heeft als extra argumenten in de constructor: sw = lijndikte , strokeWeight(); en sc = lijnkleur, stroke();
zie ook de class "Ellips" in processing
class Ellips extends Vormen {
constructor(n, h1, d, x, y, hoek, c, sw, sc) {
super(x, y, hoek);
this.n = n; this.h1 = h1; this.d = d; this.x = x; this.y = y;
this.hoek = hoek; this.c = c; this.sw = sw; this.sc = sc;
}
display() {
fill(this.c);
stroke(this.sc);
strokeWeight(this.sw);
push();
translate(this.x,this.y);
rotate(radians(this.hoek));
if (this.d == 0) ellipse(0, 0, this.n*2, this.h1*2);
if (this.d == 1) ellipse(this.n, 0, this.n*2, this.h1*2);
if (this.d == 2) ellipse(0, this.h1, this.n*2, this.h1*2);
if (this.d == 3) ellipse(-this.n, 0, this.n*2, this.h1*2);
if (this.d == 4) ellipse(0,-this.h1, this.n*2, this.h1*2);
if (this.d == 5) ellipse(0,-this.h1/2, this.n*2, this.h1*2);
pop();
}
}