Box_n4naRe terug naar de inleiding
Dit is een box met een rechthoek n x 4n en twee naar rechts wijzende parallellogrammen, lengte schuine zijde a = sqrt(2*n*n);
class Box_n4naRe extends Vormen {
Box_n4naRe(float n_, int d_, float x_, float y_, float hoek_, color c1_, color c2_, color c3_) {
super();
n = n_;
x = x_;
y = y_;
hoek = hoek_;
c1 = c1_; c2 = c2_; c3 = c3_;
d = d_;
}
void display() {
// noStroke();
pushMatrix();
translate(x, y);
rotate(radians(hoek));
beginShape();
//Vierkant
fill(c1);
if (d == 1) {vertex(0, 0); vertex(0, -4*n); vertex(n, -4*n); vertex(n, 0);}
if (d == 0) {vertex(-n, 5*n/2); vertex(-n, -3*n/2); vertex(0, -3*n/2); vertex(0, 5*n/2);}
if (d == 3) {vertex(-2*n, 5*n);vertex(-2*n, n);vertex(-n, n);vertex(-n, 5*n);}
endShape(CLOSE);
beginShape();
fill(c2);
//parallel rechts
if (d == 1) {vertex(0, -4*n); vertex(n, -5*n);vertex(2*n, -5*n);vertex(n, -4*n);}
if (d == 0) {vertex(-n, -3*n/2); vertex(0, -5*n/2);vertex(n, -5*n/2);vertex(0, -3*n/2);}
if (d == 3) {vertex(-2*n, n); vertex(-n, 0); vertex(0, 0); vertex(-n, n);}
endShape(CLOSE);
beginShape();
fill(c3);
//parallel links
if (d == 1) {vertex(n, 0); vertex(n, -4*n);vertex(2*n, -5*n);vertex(2*n, -n);}
if (d == 0) {vertex(0, 5*n/2); vertex(0, -3*n/2); vertex(n, -5*n/2); vertex(n, 3*n/2);}
if (d == 3) {vertex(-n, 5*n); vertex(-n, n); vertex(0, 0); vertex(0, 4*n);}
endShape(CLOSE);
popMatrix();
}
}
Schets met 4 boxen in draaipunt 0, met hoeken -45, 45, 135 en -135 graden
De schets maakt gebruik van de superclass: "Vormen" en de subclass: "Box_n4naRe"
Vormen vorm0;
Vormen vorm1;
Vormen vorm3;
Vormen vorm4;
void setup() {
size(960, 540);
float x = width/2;
float y = height/2;
float n = height/10;
vorm0 = new Box_n4naRe(n, 0, x, y, -45, color(255, 255, 0, 100), color(0, 255, 0, 100), color(0, 0, 255, 100));
vorm1 = new Box_n4naRe(n, 0, x, y, 45, color(255, 255, 0, 100), color(0, 255, 0, 100), color(0, 0, 255, 100));
vorm3 = new Box_n4naRe(n, 0, x, y, 135, color(255, 255, 0, 100), color(0, 255, 0, 100), color(0, 0, 255, 100));
vorm4 = new Box_n4naRe(n, 0, x, y,-135, color(255, 255, 0, 100), color(0, 255, 0, 100), color(0, 0, 255, 100));
}
void draw() {
background(#E6FBFF);
stroke(255, 0, 0);
line (width/2, 0, width/2, height);
line (0, height/2, width, height/2);
stroke(0);
vorm0.display();
vorm1.display();
vorm3.display();
vorm4.display();
}