header Tt

 

class  "Tetros ".                            terug naar de inleiding

De 5 tetromino vormen in de class "Tetros"

 

class Tetros extends Vormen { 
   
Tetros(float n_, int lr_, char letter_,  float x_, float y_, float hoek_, color c1_, float sw_, color c2_) {  
 super();  
 n = n_;   
 lr = lr_; 
 letter = letter_; 
 x = x_;   
 y = y_;   
 hoek = hoek_;  
 c1 = c1_;  
 sw = sw_; 
 c2 = c2_; 
 } 
  
void display() {  
 fill(c1);  
 strokeWeight(sw); 
 stroke(c2); 
 pushMatrix();  
 translate(x, y);  
 rotate(radians(hoek));   
 beginShape(); 
 if (letter == 'i')            {vertex(0,0);     vertex(0,-4*n);vertex(n,-4*n);  vertex(n,-0);}    
 if (letter == 'l' && lr == 1) {vertex(0,0);     vertex(0,-3*n);vertex(n,-3*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,-3*n); 
                                vertex(2*n,-3*n);vertex(2*n,0);}                                  
 if (letter == 'o')            {vertex(0,0);     vertex(0,-2*n);vertex(2*n,-2*n);vertex(2*n,0);}  
 if (letter == 't')            {vertex(0,0);     vertex(0,-n);  vertex(-n,-n);   vertex(-n,-2*n);  
                                vertex(2*n,-2*n);vertex(2*n,-n);vertex(n,-n);    vertex(n,0);} 
 if (letter == 's' && lr == 1) {vertex(0,0);     vertex(0,-n);  vertex(n,-n);    vertex(n,-2*n);  
                                vertex(3*n,-2*n);vertex(3*n,-n);vertex(2*n,-n);  vertex(2*n, 0);} 
 if (letter == 's' && lr == 0) {vertex(0,0);     vertex(0,-n);  vertex(-n,-n);   vertex(-n,-2*n);  
                                vertex(n,-2*n);  vertex(n,-n);  vertex(2*n,-n);  vertex(2*n, 0);} 
 endShape(CLOSE);  
 popMatrix();  
  }  
 }
 
voorbeeld schets met objecten van de class  "Tetros"    
de schets maakt ook gebruik van object methodes van de superclass "Vormen"

 

void setup()  { 
//fullScreen(); 
size(800,800); 
float x = width/2; 
float y = height/2; 
float n = height/18; 
int klgr = #FCD163; 
  vorm = new Vormen[14]; 
  vorm[0] = new Tetros(n*2,2,'t',x-n,    y-1.5*n,  0, color(klgr),2,  color(0)); 
  vorm[1] = new Tetros(n,  2,'t',x-n/2,  y-3*n,    0, color(255,0,0,100),n/2,color(0,255,255,100));         
  vorm[2] = new Tetros(n*2,2,'t',x+n,    y+1.5*n,180, color(klgr),2,  color(0));  
  vorm[3] = new Tetros(n,  2,'t',x+n/2,  y+3*n,  180, color(255,0,0,100),n/2,color(0,255,255,100));  
  vorm[4] = new Tetros(n*2,0,'i',x-4*n,  y-n,     90, color(klgr), 2,  color(0));  
  vorm[5] = new Tetros(n,  0,'i',x-2*n,  y-n/2,   90, color(0,255,0,100),n/2,color(255,0,0,100));        
  vorm[6] = new Tetros(n*2,0,'l',x-8*n,  y-n,      0, color(klgr),2,  color(0));      
  vorm[7] = new Tetros(n,  0,'l',x-6.5*n,y-1.5*n,  0, color(255,0,0,100),n/2,color(255,255,0,100));     
  vorm[8] = new Tetros(n*2,1,'l',x+4*n,  y-n,      0, color(klgr),2,  color(0));   
  vorm[9] = new Tetros(n,  1,'l',x+4.5*n,y-1.5*n,  0, color(255,0,0,100),n/2,color(255,255,0,100));     
  vorm[10] = new Tetros(n*2,1,'l',x-4*n, y+n,    180, color(klgr),2,  color(0));   
  vorm[11] = new Tetros(n,  1,'l',x-4.5*n,y+1.5*n,180, color(255,0,0,100),n/2,color(255,255,0,100));     
  vorm[12] = new Tetros(n*2,0,'l',x+8*n,  y+n,    180, color(klgr),2,  color(0));  
  vorm[13] = new Tetros(n,  0,'l',x+6.5*n,y+1.5*n,180, color(255,0,0,100),n/2,color(255,255,0,100));     
} 
 
void draw()  { 
    background(#E6FBFF);  
  for (int i = 0; i< 14; i++)   
  {   
  vorm[i].display();   
  }   
   
}