openobject.org

Emergence Kaleidoscope

From Physical Programming

/* creating an emergence of graphics similar to a kaleidoscope Kaleidoscope on Wikipedia [1] my GOAL is to create a variable graphics inside each triangle and reflect that like an inside of a kaleidoscope so it will create some amazing graphics. So far I have managed to create different modes of the kaleidoscope

  • note* instead of reflecting the object, with this method it is just rotating and duplicating the main triangle*/

// press '1' or '2' or '3' to choose the kaleidoscope mode

 float x1 = -150;
 float y1 = -86.6;
 float x2, x3, y2, y3 ;
 int cellSize = 50;
 int i, j;
 int a, b;
 
 void setup(){
   frameRate(60);
   size(500,500);
   background(0);
   stroke(255);
   smooth();
   fill(205);
 }
 
 void draw(){
   if ((keyPressed == true) && (key == '1')) {
     background(0);
     x1=-50;
     y1=-50;
     gridA();
   }
 
   if ((keyPressed == true) && (key == '2')) {
     background(0);
     x1=-150;
     y1=-86.6;
     gridB(x1);
   
     x1=-75;
     y1=-43.3;
     gridB(x1);
   }
   
     if ((keyPressed == true) && (key == '3')) {
     background(0);
     x1=-40;
     y1=-40;
     gridC(x1);
   
     x1=-80;
     y1=-80;
     gridC(x1);
   }
 }
 
 void gridA(){
   for (a=0;a<5;a++){
     y1+=100;
     for (b=0;b<5;b++){
       x1+=100;
     
   translate(x1,y1);
   for (j=0;j<4;j++){
     noFill();
     triangle(0, 0, -50, 50, 50, 50);
     fill(205,105,105);
     rect(-9.5,20,20,20);
     rotate(PI/2);
     }
     translate(-x1,-y1);
    }
    x1=-50;
   }
 }
 
 void gridB(float origin){
   for (a=0;a<7;a++){
       y1+=86.6;
     for (b=0;b<5;b++){
       x1+=150;
   
   translate(x1,y1);
 
   for (j=0;j<6;j++){
     noFill();
     triangle(0, 0, -cellSize/2, (sqrt(sq(cellSize)-sq(cellSize/2))), cellSize/2, (sqrt(sq(cellSize)-sq(cellSize/2))));  
     fill(205,105,105);
     rect(-9.5,20,20,20);
     rotate(PI/3);
     }
     translate(-x1,-y1);
     }
   x1=origin;  
   } 
 }
 
 void gridC(float origin){
   for (a=0;a<7;a++){
     y1+=80;
     for (b=0;b<7;b++){
       x1+=80;
       
   translate(x1,y1);
   for (j=0;j<4;j++){
     noFill();
     triangle(0, 0, 0, 40, -40, 0);
     fill(205,105,105);
     rect(-15,5,10,10);
     rotate(PI/2);
     }
     translate(-x1,-y1);
    }
    x1=origin;
   }
 }