de class "Pentos met de 12 pentomino vormen. terug naar de inleiding
De rode puntjes zijn de (0,0), en tevens rotatie punten van de pentomino's .
argumenten van de constructor 1) "n" grootte, 2) "lr" links of rechts, 3) "letter" de letter van de pentomino 4) en 5) x, y positie, 6) hoek, 7) kleur
De pentomino's I,T,U,V en X hebben geen spiegelbeeld, om dit aan te geven voer ik voor argument lr een 2 in
class Pentos extends Vormen {
Pentos(float n_, int lr_, char letter_, float x_, float y_, float hoek_, color c1_) {
super();
n = n_;
lr = lr_;
x = x_;
y = y_;
hoek = hoek_;
c1 = c1_;
letter = letter_;
}
void display() {
fill(c1);
//strokeWeight(2);
pushMatrix();
translate(x, y);
rotate(radians(hoek));
beginShape();
if (letter == 'x') {vertex(0,0); vertex(0,-n); vertex(-n,-n); vertex(-n,-2*n);
vertex(0,-2*n); vertex(0,-3*n); vertex(n,-3*n); vertex(n,-2*n);
vertex(2*n,-2*n);vertex(2*n,-n); vertex(n,-n); vertex(n,0);}
if (letter == 'p' && lr == 1) {vertex(0,0); vertex(0,-3*n); vertex(2*n,-3*n);vertex(2*n,-n); vertex(n,-n); vertex(n,0);}
if (letter == 'p' && lr == 0) {vertex(0,0); vertex(0,-n); vertex(-n,-n); vertex(-n,-3*n);vertex(n,-3*n);vertex(n,0);}
if (letter == 'w' && lr == 1) {vertex(0,0); vertex(0,-n); vertex(-n,-n); vertex(-n,-3*n);vertex(0,-3*n);
vertex(0,-2*n); vertex(n,-2*n); vertex(n,-n); vertex(2*n,-n); vertex(2*n,0);}
if (letter == 'w' && lr == 0) {vertex(0,0); vertex(0,-n); vertex(n,-n); vertex(n,-2*n); vertex(2*n,-2*n);
vertex(2*n,-3*n);vertex(3*n,-3*n);vertex(3*n,-n); vertex(2*n,-n); vertex(2*n,0);}
if (letter == 'f' && lr == 1) {vertex(0,0); vertex(0,-n); vertex(-n,-n); vertex(-n,-2*n);vertex(0,-2*n);
vertex(0,-3*n); vertex(2*n,-3*n);vertex(2*n,-2*n);vertex(n,-2*n); vertex(n,0);}
if (letter == 'f' && lr == 0) {vertex(0,0); vertex(0,-2*n); vertex(-n,-2*n); vertex(-n,-3*n);vertex(n,-3*n);
vertex(n,-2*n); vertex(2*n,-2*n);vertex(2*n,-n); vertex(n,-n); vertex(n,0);}
if (letter == 'z' && lr == 1) {vertex(0,0); vertex(0,-n); vertex(n,-n); vertex(n,-3*n);
vertex(3*n,-3*n);vertex(3*n,-2*n);vertex(2*n,-2*n);vertex(2*n,0);}
if (letter == 'z' && lr == 0) {vertex(0,0); vertex(0,-2*n); vertex(-n,-2*n); vertex(-n,-3*n);
vertex(n,-3*n); vertex(n,-n); vertex(2*n,-n); vertex(2*n,0);}
if (letter == 'u') {vertex(0,0); vertex(0,-2*n); vertex(n,-2*n); vertex(n,-n);
vertex(2*n,-n); vertex(2*n,-2*n);vertex(3*n,-2*n);vertex(3*n,0);}
if (letter == 'v') {vertex(0,0); vertex(0,-3*n); vertex(n,-3*n);
vertex(n,-n); vertex(3*n,-n); vertex(3*n,0);}
if (letter == 't') {vertex(0,0); vertex(0,-2*n); vertex(-n,-2*n); vertex(-n,-3*n);
vertex(2*n,-3*n);vertex(2*n,-2*n);vertex(n,-2*n); vertex(n,0);}
if (letter == 'l' && lr == 1) {vertex(0,0); vertex(0,-4*n); vertex(n,-4*n); vertex(n,-n); vertex(2*n,-n); vertex(2*n,0);}
if (letter == 'l' && lr == 0) {vertex(0,0); vertex(0,-n); vertex(n,-n); vertex(n,-4*n);vertex(2*n,-4*n);vertex(2*n,0);}
if (letter == 'y' && lr == 1) {vertex(0,0); vertex(0,-4*n); vertex(n,-4*n); vertex(n,-3*n);
vertex(2*n,-3*n);vertex(2*n,-2*n);vertex(n,-2*n); vertex(n,0);}
if (letter == 'y' && lr == 0) {vertex(0,0); vertex(0,-2*n); vertex(-n,-2*n); vertex(-n,-3*n);
vertex(0,-3*n); vertex(0,-4*n); vertex(n,-4*n); vertex(n,0);}
if (letter == 'n' && lr == 1) {vertex(0,0); vertex(0,-2*n); vertex(n,-2*n); vertex(n,-4*n);
vertex(2*n,-4*n);vertex(2*n,-n); vertex(n,-n); vertex(n,0);}
if (letter == 'n' && lr == 0) {vertex(0,0); vertex(0,-n); vertex(-n,-n); vertex(-n,-4*n);;
vertex(0,-4*n); vertex(0,-2*n); vertex(n,-2*n); vertex(n,0);}
if (letter == 'i') {vertex(0,0); vertex(0,-5*n); vertex(n,-5*n); vertex(n,0);}
endShape(CLOSE);
popMatrix();
}
}
voorbeeld met "Pentos"
Voor de pentomino's U, I, X, en T is in de constructor voor "lr" 2 ingevoerd, om aan te geven dat deze pentomino's geen spiegelbeeld hebben.
Vormen [] vorm;
Ruitjes ruitjespap;
void setup() {
//fullScreen();
size(800,800);
float x = width/2;
float y = height/2;
float n = height/18;
vorm = new Vormen[14];
ruitjespap = new Ruitjes(n,x,y);
vorm[0] = new Pentos(n,2,'u',x-1.5*n, y-5*n, 0, color(255,0,0,100));
vorm[1] = new Pentos(n,2,'i',x-2.5*n, y-5*n, 90, color(0,255,0,100));
vorm[2] = new Pentos(n,1,'w',x-5.5*n, y-2*n, 0, color(255,0,0,100));
vorm[3] = new Pentos(n,0,'w',x+3.5*n, y-2*n, 0, color(255,0,0,100));
vorm[4] = new Pentos(n,2,'x',x-2.5*n, y, 0, color(0,100));
vorm[5] = new Pentos(n,2,'x',x+1.5*n, y, 0, color(0,100));
vorm[6] = new Pentos(n,2,'t',x-7.5*n, y-n, 90, color(#15D8E8,150));
vorm[7] = new Pentos(n,2,'t',x+7.5*n, y, -90, color(#15D8E8,150));
vorm[8] = new Pentos(n,2,'i',x-2.5*n, y+n, 90, color(#E815DA,150));
vorm[9] = new Pentos(n,0,'w',x-3.5*n, y+n, 180, color(255,0,0,100));
vorm[10]= new Pentos(n,1,'w',x+5.5*n, y+n, 180, color(255,0,0,100));
vorm[11]= new Pentos(n,0,'p',x-1.5*n, y+6*n, 0, color(255,255,0,150));
vorm[12]= new Pentos(n,1,'p',x+n/2, y+6*n, 0, color(255,255,0,150));
vorm[13]= new Pentos(n,2,'i',x-n/2, y+8*n, 0, color(#2FFA03,150));
}
void draw() {
background(#E6FBFF);
ruitjespap.display();
for (int i = 0; i< 14; i++)
{
vorm[i].display();
}
}