• fullscreen
  • Tile.pde
  • truchetTriangles.pde
  • class Tile {
      
      int Xindex;
      int Yindex;
      
      float x, y; // X-coordinate, y-coordinate center of tile
      float tilt; 
      float angle; 
    
      // Constructor
      Tile(int Xindex, int Yindex) {
        x = Xindex * tileSize + tileSize/2 ;
        y = Yindex * tileSize + tileSize/2; 
        angle = 0;
      }
    
      void change() {
        tilt += PI/2; 
      }
    
      void display() {
        noStroke();
        fill(color(234));
        pushMatrix();
        translate(x, y);
        
        rotate(tilt);
      
        triangle(-tileSize/2 , -tileSize/2 , -tileSize/2 , tileSize/2 , tileSize/2 , tileSize/2 ); 
        fill(200);
        popMatrix();
      }
    }
    
    /* 
    Truchet tiling technique is used to create unexpected patterns. Click to generate new pattern.
    Try changing the parameter P inside the moussedPressed() function.
    In this sketch, the tiles are triangles. Experiment with other shapes.
    
    Press "s" to save as pdf (will be saved in the sketch folder).
    
    Julien Bloit
    */
    
    import processing.pdf.*;
    
    // Store Tile objects
    ArrayList paving = new ArrayList();
    Tile curTile;
    
    // tiles are quares, only one dim
    int tileSize = 0;
    int numberTiles = 0;
    int numberTilesPerRow = 0;
    
    boolean dosave=false;
    
    void setup() {
      size(600, 600);
      smooth();
      numberTilesPerRow = 10;
      tileSize = height / numberTilesPerRow ;
      numberTiles = numberTilesPerRow * numberTilesPerRow;
      
      for(int i = 0; i < numberTilesPerRow; i++){
          for(int j = 0; j < numberTilesPerRow; j++){
            paving.add(new Tile(i,j));
          }
      }
    
    }
    
    void draw() {
      if (dosave){
        beginRecord(PDF, "tiles.pdf");
      }
      background(color(#229944));
      // background(color(#000000));
      for (int i = paving.size() - 1; i>= 0; i--) {
        curTile = (Tile) paving.get(i); 
        curTile.display();
      }
      if (dosave){
        endRecord();
        dosave = false;
      }    
    }
    
    void keyPressed() {
      if (key == 's') { 
        dosave = true;
      }
    }
    
    // 
    void mousePressed() {
    // pattern parameter : try 3
    int P = 3;  
    
        int k=0;
          for (int i = paving.size() - 1; i>= 0; i--) {
            curTile = (Tile) paving.get(i); 
            if (k % P > 0)
              curTile.change();
            k++;
          }
    }
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    julien bloit

    Truchet tiles - triangles

    Add to Faves Me Likey@! 1
    You must login/register to add this sketch to your favorites.

    Truchet tiling technique is used to create unexpected patterns. Click to generate new pattern.
    Try changing the parameter P inside the moussedPressed() function.
    In this sketch, the tiles are triangles. Experiment with other shapes.

    Press "s" to save as pdf (will be saved in the sketch folder).

    Julien Bloit

    You need to login/register to comment.