Permutations of 2x2 Truchet Tiles

edited May 2016 in How To...

Truchet base tiles bordered.png
By Paolo Gibellini Original uploader was P.gibellini at it.wikipedia - Transferred from it.wikipedia; transfer was stated to be made by User:p.gibellini. (Original text : myself), Public Domain, https://commons.wikimedia.org/w/index.php?curid=4158376

Given the above image of Truchet Tiles. I would like to draw out every single permutation of Truchet Tiles via processing. However with an important caveat. The traditional Truchet Tile has half of it's square area filled by a black triangle. I would like to treat a single tile as composed of 4 "Truchet Tiles" (or a 2x2 Truchet Tile).

What the image above is missing (in my opinion) however and I would like to include is the case when a tile may be completely white. So all together each of the 4 squares that make up one 2x2 Truchet Tile has 5 distinct possibilities.

That should result in (5 * 5 * 5 * 5=) 625 total permutations!

So in sum, I would like to be able to first procedurally draw out every single one of these permutations, and then eventually be able to store them somehow and randomly generate patterns that are composed of different combinations of these unique looking tiles.

I am curious as to whether these patterns will look different or significantly depart from traditional truchet tiles. When truchet tiles are normally in a pattern, they may end up neighboring each other to create 2x2 Truchet tiles, but I wonder if making the tiles grouped together like this to begin with will result in more interesting 4x4 neighbors.

truchet_2by2

In the above image, just to clarify. The red outlines a traditional truchet tile. In blue is outlined a 2x2 truchet tile, which I am interested in permutating.

Answers

  • edited May 2016 Answer ✓

    Step 1: Draw all 625 possible combinations.

    int type[] = { 
      0, 0, 0, 0
    };
    
    void setup() {
      size(501, 501);
      background(255);
      fill(0);
      noStroke();
      for (int y=0; y<25; y++) {
        for (int x=0; x<25; x++) {
          pushMatrix();
          translate(20*x, 20*y);
          tile(type[0]);
          translate(10, 0);
          tile(type[1]);
          translate(-10, 10);
          tile(type[2]);
          translate(10, 0);
          tile(type[3]);
          translate(-10,-10);
          next_type();
          pushStyle();
          noFill();
          stroke(0, 0, 255);
          rect(0, 0, 20, 20);
          popStyle();      
          popMatrix();
        }
      }
      noLoop();
    }
    
    void tile(int kind) {
      if (kind == 1) triangle(0, 0, 10, 0, 0, 10);
      if (kind == 2) triangle(10, 0, 10, 10, 0, 10);
      if (kind == 3) triangle(0, 0, 10, 0, 10, 10);
      if (kind == 4) triangle(0, 0, 10, 10, 0, 10);
    }
    
    void next_type() {
      type[3]++;
      if (type[3]==5) {
        type[3]=0;
        type[2]++;
        if (type[2]==5) {
          type[2]=0;
          type[1]++;
          if (type[1]==5) {
            type[1]=0;
            type[0]++;
            if (type[0]==5) {
              type[0]=0;
            }
          }
        }
      }
    }
    
  • You can use save to store results

    You could also store the pattern as an abstract String (basically type) on the hard drive as a String, load it with another new sketch

Sign In or Register to comment.