Skip to content

Truchet Tiles and 10 PRINT

Split the picture into cells and make one small choice in each: a maze from a diagonal, winding paths from two arcs.

How it works

Loop over the cells row by row, and in each one choose between two ways of drawing the same tile. The Commodore 64 program 10 PRINT CHR$(205.5+RND(1)); : GOTO 10 printed one of two diagonal characters at random, for ever, and a maze appeared: that is the first example.

Truchet tiles have a quarter-circle in two opposite corners, turned one of two ways. Every arc starts and ends at the middle of a cell's edge, so it always meets an arc in the next cell, and they join into long winding paths.

The choice is a random number, but a repeatable one: the shapes starter calls SetRandomSeed before every frame, so frand gives the same numbers each time and the picture stays still until R picks another seed. cellrand(i, j) gives a fixed random number for a cell without depending on drawing order.

The choice doesn't have to be random. Anything worked out from the cell's position (its distance from the centre, an XOR of its numbers, a noise value) gives a pattern you can control.

The C is for the raylib shapes starter.

10 PRINT: a random diagonal in each cell

static void draw(float t)
{
    const int s = 40;
    clear(PAPER);
    for (int y = 0; y < H; y += s)
        for (int x = 0; x < W; x += s) {
            if (frand(0, 1) < 0.5f) DrawLineEx((Vector2){ x, y }, (Vector2){ x + s, y + s }, 6, INK);
            else DrawLineEx((Vector2){ x + s, y }, (Vector2){ x, y + s }, 6, INK);
        }
}
function draw(t) {
  const s = 40;
  clear(PAPER);
  for (let y = 0; y < H; y += s)
    for (let x = 0; x < W; x += s) {
      if (frand(0, 1) < 0.5) DrawLineEx(Vector2(x, y), Vector2(x + s, y + s), 6, INK);
      else DrawLineEx(Vector2(x + s, y), Vector2(x, y + s), 6, INK);
    }
}

Truchet tiles

static void draw(float t)
{
    const int s = 60;
    const float r = s / 2.0f;
    clear(PAPER);
    for (int y = 0; y < H; y += s)
        for (int x = 0; x < W; x += s) {
            if (frand(0, 1) < 0.5f) {
                DrawRing((Vector2){ x, y }, r - 3, r + 3, 0, 90, 24, INK);
                DrawRing((Vector2){ x + s, y + s }, r - 3, r + 3, 180, 270, 24, INK);
            } else {
                DrawRing((Vector2){ x + s, y }, r - 3, r + 3, 90, 180, 24, INK);
                DrawRing((Vector2){ x, y + s }, r - 3, r + 3, 270, 360, 24, INK);
            }
        }
}
function draw(t) {
  const s = 60;
  const r = s / 2;
  clear(PAPER);
  for (let y = 0; y < H; y += s)
    for (let x = 0; x < W; x += s) {
      if (frand(0, 1) < 0.5) {
        DrawRing(Vector2(x, y), r - 3, r + 3, 0, 90, 24, INK);
        DrawRing(Vector2(x + s, y + s), r - 3, r + 3, 180, 270, 24, INK);
      } else {
        DrawRing(Vector2(x + s, y), r - 3, r + 3, 90, 180, 24, INK);
        DrawRing(Vector2(x, y + s), r - 3, r + 3, 270, 360, 24, INK);
      }
    }
}

Not random: size from the distance

remap moves the distance, 0 to 424 (the corner), to a radius from 18 down to 2.

static void draw(float t)
{
    clear(PAPER);
    for (int y = 20; y < H; y += 40)
        for (int x = 20; x < W; x += 40) {
            float d = dist(x, y, W / 2, H / 2);
            DrawCircle(x, y, remap(d, 0, 424, 18, 2), INK);
        }
}
function draw(t) {
  clear(PAPER);
  for (let y = 20; y < H; y += 40)
    for (let x = 20; x < W; x += 40) {
      let d = dist(x, y, W / 2, H / 2);
      DrawCircle(x, y, remap(d, 0, 424, 18, 2), INK);
    }
}