Skip to content

Your own tilings ​

Two specs let you bring your own tiles. Nothing checks that your tiles fit together, so overlapping or gappy input gives an overlapping or gappy layout.

periodic: two L-trominoes, repeated
periodic: two L-trominoes, repeated
tiles: your own polygons, as given
tiles: your own polygons, as given
ts
import { createLayout, periodic, tiles } from "@andamento/core";
import { renderToString } from "@andamento/svg";

/** A repeating tiling of your own: two L-trominoes filling a 3 × 2 block, copied along a and b. */
export function trominoes() {
  const tiling = periodic({
    a: { x: 60, y: 0 },
    b: { x: 20, y: 40 },
    motif: [
      { polygon: [{ x: 0, y: 0 }, { x: 40, y: 0 }, { x: 40, y: 20 }, { x: 20, y: 20 }, { x: 20, y: 40 }, { x: 0, y: 40 }] },
      { polygon: [{ x: 40, y: 0 }, { x: 60, y: 0 }, { x: 60, y: 40 }, { x: 20, y: 40 }, { x: 20, y: 20 }, { x: 40, y: 20 }] },
    ],
  });
  const layout = createLayout({ region: { x: 0, y: 0, width: 240, height: 150 }, tiling, gap: 2, cornerRadius: 2 });
  return renderToString(layout, { fill: ["#2a9d8f", "#e9c46a", "#f4a261", "#e76f51"], background: "#264653" });
}

/** Your own polygons, used as given: here a fan of wedges. */
export function fan() {
  const wedges = Array.from({ length: 9 }, (_, i) => {
    const a0 = Math.PI + (i / 9) * Math.PI, a1 = Math.PI + ((i + 1) / 9) * Math.PI;
    const at = (a: number, r: number) => ({ x: 120 + r * Math.cos(a), y: 140 + r * Math.sin(a) });
    return [
      { polygon: [at(a0, 30), at(a0, 75), at(a1, 75), at(a1, 30)], id: `in${i}` },
      { polygon: [at(a0, 75), at(a0, 130), at(a1, 130), at(a1, 75)], id: `out${i}`, protoTile: 1 },
    ];
  }).flat();
  const layout = createLayout({ region: { x: 0, y: 0, width: 240, height: 145 }, tiling: tiles({ tiles: wedges }), gap: 2.5, cornerRadius: 3 });
  return renderToString(layout, { fill: ["#e76f51", "#f4a261", "#e9c46a"], background: "#fbf8f3" });
}

Repeating tilings: periodic ​

periodic({ a, b, motif }) copies the motif (one or more polygons, in region units) to every i·a + j·b. It gets everything the built-in patterns get: gap, margin, edges, rounding, neighbors, rotation, origin, and stable lattice-based ids.

checkPeriodic(spec) samples one lattice cell and reports the fraction of points covered by no tile (gaps) or by several (overlaps), plus whether any polygon crosses itself:

ts
checkPeriodic(trominoes); // { ok, gaps, overlaps, selfIntersecting, cellArea, motifArea }

periodicDefinition(spec) gives the { a, b, motif } of any built-in repeating pattern, as a starting point for your own.

Your own polygons: tiles ​

tiles({ tiles: [{ polygon, id?, protoTile? }, …] }) uses your polygons as they are. rotation and origin don't apply. Give each tile an id to keep it stable across changes, and a protoTile to tell kinds of tile apart.

Polygons can be non-convex but must be simple: their outlines must not cross themselves.

Lower-level helpers ​

The building blocks are exported too:

  • Coloring: colorCells (neighbor-aware color indices).
  • Polygon operations: insetPolygon, roundedPolygon, overlay.
  • Generators: voronoiCells, delaunayTriangles and generateSubstitution (for substitution tilings like Penrose).

Hat tiling and isohedral tilings after Craig S. Kaplan's hatviz and Tactile (BSD 3-Clause).