schets met boxen in een driehoekformatie. terug naar de inleiding
De boxen zijn objecten van de class "Boxr" , de code van deze class staat onder deze schets.
2*hn is de breedte van de box (hn is de hoogte van de gelijkzijdige driehoek n)
argumenten van de constructor:
1) = grootte van de box, 2) = grootte van de ruiten, 3) en 4) = positie van de box,
5) = kleur van de ruiten, 6) = kleur van de top, 7) = kleur li vlak, 8) = kleur re vlak
float r = grootte van de ruit als deel van de vlakken van de box. Met r = 0; is de ruit onzichtbaar
Met r = 1 is de ruit net zo groot als de box en heeft de box de kleur klr
int b = 3;
Boxr[] box1 = new Boxr[b]; Boxr[] box2 = new Boxr[b];
Boxr[] box3 = new Boxr[b-1]; Boxr[] box4 = new Boxr[b-1];
Boxr[] box5 = new Boxr[b-1]; Boxr[] box6 = new Boxr[b-1];
Boxr[] box7 = new Boxr[b-2]; Boxr[] box8 = new Boxr[b-2];
Boxr[] box9 = new Boxr[b-2]; Boxr[] box10 = new Boxr[b-2];
Boxr boxm1; Boxr boxm2; Boxr boxm3;
void setup()
{
size(1500, 600);
//fullScreen();
float x = width/2; float y = height/2; float n = height/12;
float hn = sqrt(3*n*n/4);
int kl1 = #10AFAB; int kl2 = #439391; int kl3 = #73F7F4; int klr = #0C6462;
// int kl1 = #FC4046; int kl2 = #FC6369; int kl3 = #FFB9BC; int klr = #C6181E;
float r = 0.5;
for (int i = 0;i < b;i++) box1[i] = new Boxr(n,n*r,x+hn+2*hn*i, y-3*n, color(klr),color(kl1),color(kl2),color(kl3));
for (int i = 0;i < b;i++) box2[i] = new Boxr(n,n*r,x-hn-2*hn*i, y-3*n, color(klr),color(kl1),color(kl3),color(kl2));
for (int i = 0;i < b-1;i++) box3[i] = new Boxr(n,n*r,x+2*hn+2*hn*i,y-1.5*n,color(klr),color(kl1),color(kl2),color(kl3));
for (int i = 0;i < b-1; i++)box4[i] = new Boxr(n,n*r,x-2*hn-2*hn*i,y-1.5*n,color(klr),color(kl1),color(kl3),color(kl2));
for (int i = 0;i < b-1;i++) box5[i] = new Boxr(n,n*r,x+hn+2*hn*i, y, color(klr),color(kl1),color(kl2),color(kl3));
for (int i = 0;i < b-1;i++) box6[i] = new Boxr(n,n*r,x-hn-2*hn*i, y, color(klr),color(kl1),color(kl3),color(kl2));
for (int i = 0;i < b-2;i++) box7[i] = new Boxr(n,n*r,x+2*hn+2*hn*i,y+1.5*n,color(klr),color(kl1),color(kl2),color(kl3));
for (int i = 0;i < b-2;i++) box8[i] = new Boxr(n,n*r,x-2*hn-2*hn*i,y+1.5*n,color(klr),color(kl1),color(kl3),color(kl2));
for (int i = 0;i < b-2;i++) box9[i] = new Boxr(n,n*r,x+hn+2*hn*i, y+3*n, color(klr),color(kl1),color(kl2),color(kl3));
for (int i = 0;i < b-2;i++)box10[i] = new Boxr(n,n*r,x-hn-2*hn*i, y+3*n, color(klr),color(kl1),color(kl3),color(kl2));
boxm1 = new Boxr(n,n*r, x, y-1.5*n, color(klr),color(kl1),color(kl3),color(kl3));
boxm2 = new Boxr(n,n*r, x, y+1.5*n, color(klr),color(kl1),color(kl3),color(kl3));
boxm3 = new Boxr(n,n*r, x, y+4.5*n, color(klr),color(kl1),color(kl3),color(kl3));
}
void draw()
{
background(#E6FBFF);
for (int i = 0; i < b; i++) box1[i].display();
for (int i = 0; i < b; i++) box2[i].display();
for (int i = 0; i < b-1; i++) box3[i].display();
for (int i = 0; i < b-1; i++) box4[i].display();
for (int i = 0; i < b-1; i++) box5[i].display();
for (int i = 0; i < b-1; i++) box6[i].display();
for (int i = 0; i < b-2; i++) box7[i].display();
for (int i = 0; i < b-2; i++) box8[i].display();
for (int i = 0; i < b-2; i++) box9[i].display();
for (int i = 0; i < b-2; i++) box10[i].display();
boxm1.display();
boxm2.display();
boxm3.display();
}
de class "Boxr"
//classe van een box met ruiten in de drie vlakken
class Boxr
{
float n; float r; float x; float y;
color cr; color c1; color c2; color c3;
//constructor: n = grootte van de box, r = grootte van de ruiten, x en y = positie van de box,
//cr = kleur van de ruiten, c1 = kleur van de top, c2 = kleur li vlak, c3 = kleur re vlak
Boxr( float n_, float r_, float x_, float y_, color cr_, color c1_, color c2_, color c3_)
{
n = n_; r = r_; x = x_; y = y_;
cr = cr_; c1 = c1_; c2 = c2_; c3 = c3_;
}
void display()
{
float hn = sqrt(3*n*n/4);
float hg = sqrt(3*r*r/4);
float rx1 = (n/2-r/2)*cos(radians(30));
float ry1 = (n/2-r/2)*sin(radians(30));
float ry2 = ry1+r;
float rx3 = (r+(n/2-r/2))*cos(radians(30));
float ry3 = (r+(n/2-r/2))*sin(radians(30));
float ry4 = ry3-r;
beginShape();
//top van de box
fill(c1);
vertex(x, y); vertex(x-hn, y-n/2); vertex(x, y-n); vertex(x+hn, y-n/2);
endShape(CLOSE);
beginShape();
//ruit in de top van de box
fill(cr);
vertex(x, y-(n/2-r/2)); vertex(x-hg, y-n/2); vertex(x, y-(n/2+r/2)); vertex(x+hg, y-n/2);
endShape(CLOSE);
beginShape();
//li vlak van de box
fill(c2);
vertex(x, y); vertex(x-hn, y-n/2); vertex(x-hn, y+(n-n/2)); vertex(x, y+n);
endShape(CLOSE);
beginShape();
fill(cr);
//ruit in li vlak
vertex(x-rx1, y+ry1); vertex(x-rx1, y+ry2); vertex(x-rx3, y+ry3); vertex(x-rx3, y+ry4);
endShape(CLOSE);
beginShape();
fill(c3);
//re vlak is li vlak gespiegeld in de y as
vertex(x, y); vertex(x+hn, y-n/2); vertex(x+hn, y+(n-n/2)); vertex(x, y+n);
endShape(CLOSE);
beginShape();
//ruit in re vlak is de ruit in li vlak gespiegeld in de y as
fill(cr);
vertex(x+rx1, y+ry1); vertex(x+rx1, y+ry2); vertex(x+rx3, y+ry3); vertex(x+rx3, y+ry4);
endShape(CLOSE);
}
}