Skip to content

Examples ​

Every picture here is drawn by the code under it, run when the site is built. The code uses createLayout from @andamento/core and renderToString from @andamento/svg, but the same options work in every renderer. photos, scenePixels and sceneImage are made-up pictures from shared.ts.

Decorative ​

Terrazzo ​

Code
ts
/** Terrazzo: small random stones in a pale ground. */
export function terrazzo() {
  const layout = createLayout({ region, tiling: voronoi({ size: 9, relax: 1, seed: 11 }), gap: 2.2, cornerRadius: 2.5 });
  return renderToString(layout, { fill: randomFill(["#d9a38a", "#8f9e8b", "#e8d5b5", "#c6c1b9", "#b5654a", "#efe6da", "#efe6da"], 3), background: "#f3eee6" });
}

Tumbling blocks ​

Code
ts
/** Tumbling blocks: rhombs shaded by face, raised. */
export function blocks() {
  const layout = createLayout({ region, tiling: rhombille({ size: 22 }), gap: 1.5, cornerRadius: 1 });
  return renderToString(layout, { fill: protoTileFill(["#f2e8cf", "#bc4749", "#386641"]), background: "#2b2b2b", relief: { strength: 0.3 } });
}

An Escher-style tessellation ​

Code
ts
/** An Escher-style tessellation: one shape in two orientations. */
export function escher() {
  const layout = createLayout({ region, tiling: isohedral({ ih: 28, size: 56, amount: 0.25 }), gap: 1.5 });
  return renderToString(layout, { fill: protoTileFill(["#264653", "#e9c46a"]), background: "#fbf8f3" });
}

A random Mondrian ​

Code
ts
/** A Mondrian: random rectangles, mostly white, with black lines. */
export function painting() {
  const layout = createLayout({ region, tiling: mondrian({ minSize: 28, maxSize: 110, splitChance: 0.45, snap: 4, seed: 9 }), gap: 3.5, margin: 3.5 });
  return renderToString(layout, { fill: randomFill(["#f5f1e8", "#f5f1e8", "#f5f1e8", "#f5f1e8", "#d72d2d", "#1f4fa3", "#f2c230"], 4), background: "#111" });
}

The hat monotile ​

The 2023 "einstein": one shape that tiles the plane but never repeats. About one hat in seven is mirrored; here they're red.

Code
ts
/** The hat monotile: the mirrored hats (protoTile 4) picked out. */
export function hats() {
  const layout = createLayout({ region, tiling: hat({ size: 22 }), origin: middle, gap: 1.2 });
  return renderToString(layout, { fill: protoTileFill(["#a8dadc", "#cfe8e9", "#86c5c9", "#bfe0e2", "#e63946"]), background: "#1d3557" });
}

Spectres ​

Code
ts
/** The spectre, in a sunset gradient. */
export function spectres() {
  const layout = createLayout({ region, tiling: spectre({ size: 22 }), origin: middle, gap: 1.2, cornerRadius: 1 });
  return renderToString(layout, { fill: gradientFill(["#355c7d", "#6c5b7b", "#c06c84", "#f67280", "#f8b195"], { angle: 60 }), background: "#fbf8f3" });
}

A Penrose star ​

Code
ts
/** Penrose rhombs radiating from the star at the center. */
export function penroseStar() {
  const layout = createLayout({ region, tiling: penrose({ size: 20 }), origin: middle, gap: 1.2 });
  return renderToString(layout, { fill: gradientFill(["#ffd166", "#ef476f", "#3a0ca3"], { shape: "radial" }), background: "#fbf8f3" });
}

Mermaid scales ​

Code
ts
/** Mermaid scales, darkening down the page. */
export function scales() {
  const layout = createLayout({ region, tiling: fishScale({ size: 26 }), gap: 1.5 });
  return renderToString(layout, { fill: gradientFill(["#b8f2e6", "#5e9ea0", "#264653"], { angle: 90 }), background: "#fbf8f3", relief: { strength: 0.25 } });
}

Floors and walls ​

A bathroom floor ​

Code
ts
/** A bathroom floor: hopscotch tiles with white grout, raised. */
export function bathroom() {
  const layout = createLayout({ region, tiling: hopscotch({ large: 46, small: 23 }), rotation: 12, gap: 2.5, cornerRadius: 1.5 });
  return renderToString(layout, { fill: protoTileFill(["#e8e4dc", "#2f4858"]), background: "#fdfcf9", relief: { shadow: 1.2, strength: 0.3 } });
}

Octagons and squares ​

Code
ts
/** Octagons and squares: a classic floor. */
export function floor() {
  const layout = createLayout({ region, tiling: octagonSquare({ size: 24 }), rotation: 45, gap: 1.5, cornerRadius: 1 });
  return renderToString(layout, { fill: protoTileFill(["#f1e3c8", "#7f2b1d"]), background: "#c9b79c", relief: { strength: 0.25, shadow: 1 } });
}

A wall with a door and a window, an arch, a round patio ​

Code
ts
import { createLayout, herringbone, hexagonal, runningBond, voronoi } from "@andamento/core";
import { renderToString } from "@andamento/svg";

/** A wall with a door and a window: an L-shaped region with two holes. */
export function wall() {
  const layout = createLayout({
    region: [
      { x: 0, y: 0 }, { x: 180, y: 0 }, { x: 180, y: 60 }, { x: 260, y: 60 },
      { x: 260, y: 160 }, { x: 0, y: 160 },
    ],
    holes: [
      { x: 30, y: 70, width: 40, height: 90 }, // door, open at the bottom edge
      { x: 110, y: 30, width: 50, height: 40 }, // window
    ],
    tiling: runningBond({ width: 26, height: 12 }),
    gap: 1.5,
    margin: 3,
  });
  return renderToString(layout, { fill: ["#c8673c", "#b4532a", "#d97f52", "#a84a24"], background: "#efe7dc" });
}

/** An arch: the curve is approximated with short straight segments. */
export function arch() {
  const top = Array.from({ length: 33 }, (_, i) => {
    const a = Math.PI - (i / 32) * Math.PI;
    return { x: 100 + 80 * Math.cos(a), y: 90 - 80 * Math.sin(a) };
  });
  const layout = createLayout({
    region: [{ x: 20, y: 200 }, ...top, { x: 180, y: 200 }],
    tiling: herringbone({ length: 36, width: 12 }),
    gap: 1.2,
    margin: 3,
  });
  return renderToString(layout, { fill: ["#e9c46a", "#f4a261", "#e8b25e"], background: "#5b4636" });
}

/** A round region, cut from irregular stones. */
export function round() {
  const circle = Array.from({ length: 64 }, (_, i) => ({ x: 100 + 90 * Math.cos((i / 64) * 2 * Math.PI), y: 100 + 90 * Math.sin((i / 64) * 2 * Math.PI) }));
  const layout = createLayout({ region: circle, tiling: voronoi({ size: 26, seed: 4 }), gap: 2.5, cornerRadius: 3 });
  return renderToString(layout, { fill: ["#8ab17d", "#a7c59a", "#6d9a63", "#bcd3a8"], background: "#3d4a3a" });
}

/** A hole inside a single tile becomes a hole in that cell. */
export function holed() {
  const layout = createLayout({
    region: { x: 0, y: 0, width: 200, height: 120 },
    holes: [{ x: 92, y: 52, width: 16, height: 16 }],
    tiling: hexagonal({ size: 42 }),
    gap: 3,
  });
  return renderToString(layout, { fill: ["#2a9d8f", "#e9c46a", "#f4a261", "#e76f51"], background: "#264653" });
}

Mosaics ​

Rows flowing round the sun ​

Code
ts
/** A mosaic: rows ringing the sun and following the coast, colored from the picture. */
export function mosaic() {
  const pixels = scenePixels();
  const layout = createLayout({
    region,
    tiling: flow({
      size: 5,
      centers: [{ x: 149, y: 75 }],
      guides: [{ points: [{ x: 0, y: 99 }, { x: 240, y: 99 }] }],
      followEdges: true,
    }),
    gap: 0.6,
  });
  return renderToString(layout, { fill: imageFill(pixels), background: "#2b2524" });
}

Stones sized by the picture's detail ​

Code
ts
import { createLayout, edgeSize, gradientFill, grid, hexagonal, imageFill, imageSize, radialSize, voronoi } from "@andamento/core";
import { renderToString } from "@andamento/svg";
import { scenePixels } from "./shared";

const region = { x: 0, y: 0, width: 240, height: 160 };

/** Small hexagons round a point, growing outwards. */
export function radial() {
  const layout = createLayout({
    region,
    tiling: hexagonal({ size: 22 }),
    sizeAt: radialSize({ center: { x: 150, y: 70 }, radius: 140, inner: 0.25 }),
    gap: 1,
  });
  return renderToString(layout, { fill: gradientFill(["#f6d365", "#e76f51", "#264653"], { shape: "radial" }), background: "#fbf8f3" });
}

/** Small squares along the edges: a grid nests exactly, like a quadtree. */
export function edges() {
  const layout = createLayout({
    region,
    tiling: grid({ width: 32 }),
    sizeAt: edgeSize([{ x: 0, y: 0 }, { x: 240, y: 0 }, { x: 240, y: 160 }, { x: 0, y: 160 }], { distance: 40, edge: 0.25 }),
    gap: 1,
  });
  return renderToString(layout, { fill: ["#e76f51", "#f4a261", "#e9c46a", "#f1dca7"], background: "#fbf8f3" });
}

/** Small stones where a picture is dark, colored from the same picture: a mosaic. */
export function picture() {
  const pixels = scenePixels();
  const layout = createLayout({
    region,
    tiling: voronoi({ size: 12, seed: 2 }),
    sizeAt: imageSize(pixels, region, { dark: 0.35 }),
    gap: 0.6,
  });
  return renderToString(layout, { fill: imageFill(pixels), background: "#1b1b24" });
}

From a box of twelve colors ​

Code
ts
/** A mosaic: each tile the average color of a picture under it, snapped to a box of tile colors. */
export function mosaic() {
  const tileColors = ["#1d1b3a", "#3b2f63", "#7a3b69", "#c44f78", "#e8766b", "#f6a35c", "#ffd58a", "#fff1cf", "#30263f", "#5a3d5c", "#d66868", "#26355f"];
  const layout = createLayout({ region: { x: 0, y: 0, width: 240, height: 160 }, tiling: penrose({ size: 7 }), origin: { x: 120, y: 80 }, gap: 0.5 });
  return {
    "mosaic-average": renderToString(layout, { fill: imageFill(scenePixels()), background: "#141418" }),
    "mosaic-palette": renderToString(layout, { fill: imageFill(scenePixels(), { palette: tileColors }), background: "#141418" }),
  };
}

A jigsaw ​

Code
ts
/** One picture across all the tiles: a jigsaw. */
export function backdrop() {
  const layout = createLayout({ region: { x: 0, y: 0, width: 240, height: 160 }, tiling: jigsaw({ size: 40, seed: 5 }), gap: 1.5 });
  return renderToString(layout, { backdrop: sceneImage(), background: "#f1ece4", relief: { shadow: 1 } });
}

Photo walls ​

Code
ts
import { createLayout, hexagonal } from "@andamento/core";
import { renderToString } from "@andamento/svg";
import { photos } from "./shared";

/** A photo wall of hexagons, with a featured flower of seven in the middle and raised tiles. */
export default function hero() {
  const layout = createLayout({
    region: { x: 0, y: 0, width: 300, height: 200 },
    tiling: hexagonal({ size: 26 }),
    gap: 3,
    margin: 4,
    cornerRadius: 4,
    features: [{ tiles: 7 }],
  });
  return renderToString(layout, {
    images: photos(40),
    background: "#e9e3d8",
    relief: { shadow: 1.5 },
  });
}

Important photos ​

Every fifth photo spans 4 tiles
Every fifth photo spans 4 tiles
The first spans 9
The first spans 9
Code
ts
import { createLayout, grid, hexagonal, weightedLayout } from "@andamento/core";
import { renderToString } from "@andamento/svg";
import { photos } from "./shared";

// #region features
/** Featured tiles: a flower of 7 hexagons in the middle, and 3 more near the top left. */
export function features() {
  const layout = createLayout({
    region: { x: 0, y: 0, width: 260, height: 170 },
    tiling: hexagonal({ size: 22 }),
    gap: 2.5,
    cornerRadius: 3,
    features: [{ tiles: 7 }, { tiles: 3, at: { x: 50, y: 40 } }],
  });
  return renderToString(layout, { images: photos(60), background: "#e9e3d8" });
}
// #endregion features

// #region weights
/** Important items: every fifth photo spans 4 tiles, placed where it falls in the order. */
export function weights() {
  const items = photos(32);
  const weights = items.map((_, i) => (i % 5 === 0 ? 4 : 1));
  const { layout } = weightedLayout(
    { region: { x: 0, y: 0, width: 260, height: 170 }, tiling: grid({ width: 40, height: 30 }), gap: 3, cornerRadius: 3 },
    weights,
    { fit: true },
  );
  return renderToString(layout, { images: items, background: "#e9e3d8" });
}
// #endregion weights

/** A hero: one item that spans 9 tiles, with the rest round it. */
export function hero() {
  const items = photos(30);
  const { layout } = weightedLayout(
    { region: { x: 0, y: 0, width: 260, height: 170 }, tiling: grid({ width: 40, height: 34 }), gap: 3, cornerRadius: 3 },
    items.map((_, i) => (i === 0 ? 9 : 1)),
    { fit: true },
  );
  return renderToString(layout, { images: items, background: "#e9e3d8" });
}

Every photo whole ​

Code
ts
/** Safe areas: each photo whole and uncropped, as big as its hexagon allows. */
export function contain() {
  const layout = createLayout({ region: { x: 0, y: 0, width: 220, height: 140 }, tiling: hexagonal({ size: 30 }), gap: 3, cornerRadius: 5 });
  return renderToString(layout, { images, imageAspects: aspects, imageFit: "contain", fill: ["#2f3e46", "#354f52", "#52796f"], background: "#1e2b30" });
}

Shared material ​

The made-up photos and the sunset scene used above:

shared.ts
ts
/**
 * Shared material for the manual's examples: placeholder photos and a painted scene, both
 * made in code so the examples need no image files.
 */
import type { Layout, Pixels } from "@andamento/core";
import { regionPath } from "@andamento/svg";

/** `count` placeholder photos (soft landscapes as SVG data URIs), every third one portrait. */
export function photos(count: number): string[] {
  return Array.from({ length: count }, (_, i) => {
    const hue = (i * 47 + 20) % 360;
    const [w, h] = i % 3 === 1 ? [300, 400] : [400, 300];
    const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}" preserveAspectRatio="xMidYMid slice">
<defs><linearGradient id="s" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="hsl(${hue} 55% 74%)"/><stop offset="1" stop-color="#fff8ee"/></linearGradient></defs>
<rect width="${w}" height="${h}" fill="url(#s)"/>
<circle cx="${w * (0.3 + ((i * 13) % 40) / 100)}" cy="${h * 0.33}" r="${h * 0.1}" fill="hsl(${(hue + 180) % 360} 85% 86%)"/>
<path d="M0 ${h * 0.7} Q ${w * 0.3} ${h * 0.45} ${w * 0.6} ${h * 0.62} T ${w} ${h * 0.55} V ${h} H 0Z" fill="hsl(${(hue + 15) % 360} 35% 60%)"/>
<path d="M0 ${h * 0.85} Q ${w * 0.4} ${h * 0.6} ${w} ${h * 0.8} V ${h} H 0Z" fill="hsl(${(hue + 30) % 360} 40% 42%)"/>
</svg>`;
    return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
  });
}

/** Width / height of each of `photos(count)`. */
export const photoAspects = (count: number) => Array.from({ length: count }, (_, i) => (i % 3 === 1 ? 0.75 : 4 / 3));

/** Where each photo's sun is: a focal point for `photos(count)`. */
export const photoFocus = (count: number) =>
  Array.from({ length: count }, (_, i) => ({ x: 0.3 + ((i * 13) % 40) / 100, y: 0.33, aspect: i % 3 === 1 ? 0.75 : 4 / 3 }));

type RGB = [number, number, number];
const mix = (a: RGB, b: RGB, t: number): RGB => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
const smooth = (e0: number, e1: number, x: number) => {
  const t = Math.min(1, Math.max(0, (x - e0) / (e1 - e0)));
  return t * t * (3 - 2 * t);
};

/** The scene's color at (u, v), fractions of its width and height: a sunset over the sea. */
function sceneColor(u: number, v: number, aspect: number): RGB {
  const horizon = 0.62;
  const sun = { u: 0.62, v: 0.47, r: 0.13 };
  const du = (u - sun.u) * aspect, dv = v - sun.v;
  const d = Math.hypot(du, dv);
  let c: RGB;
  if (v < horizon) {
    const t = v / horizon;
    c = t < 0.55 ? mix([43, 45, 110], [196, 79, 120], t / 0.55) : mix([196, 79, 120], [252, 170, 90], (t - 0.55) / 0.45);
    c = mix(c, [255, 226, 160], 0.55 * Math.exp(-((d / 0.32) ** 2)));
    if (d < sun.r) c = mix([255, 214, 120], [255, 246, 214], 1 - d / sun.r);
  } else {
    const t = (v - horizon) / (1 - horizon);
    c = mix([214, 104, 104], [26, 42, 92], smooth(0, 1, t));
    // The sun's path on the water, broken by waves.
    const wave = Math.sin(v * 140 + Math.sin(u * 30) * 2) > 0.2 ? 1 : 0.35;
    c = mix(c, [255, 200, 130], wave * Math.exp(-((du / (0.05 + 0.12 * t)) ** 2)) * (1 - 0.6 * t));
  }
  // A headland on the left.
  const land = horizon - 0.16 * Math.exp(-(((u - 0.1) / 0.16) ** 2)) - 0.04 * Math.exp(-(((u - 0.3) / 0.08) ** 2));
  if (v > land && v < horizon + 0.03 * smooth(0.35, 0, u) && u < 0.45) c = mix([40, 32, 60], [70, 48, 80], (v - land) * 4);
  return c;
}

/** The scene as RGBA pixels (for `imageFill` and `imageSize`). */
export function scenePixels(width = 240, height = 160): Pixels {
  const data = new Uint8ClampedArray(width * height * 4);
  for (let y = 0; y < height; y++) {
    for (let x = 0; x < width; x++) {
      const [r, g, b] = sceneColor((x + 0.5) / width, (y + 0.5) / height, width / height);
      data.set([r, g, b, 255], (y * width + x) * 4);
    }
  }
  return { width, height, data };
}

/** The same scene as an SVG data URI (for `backdrop`), drawn with gradients. */
export function sceneImage(width = 600, height = 400): string {
  const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 600 400" preserveAspectRatio="xMidYMid slice">
<defs>
<linearGradient id="sky" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#2b2d6e"/><stop offset="0.55" stop-color="#c44f78"/><stop offset="1" stop-color="#fcaa5a"/></linearGradient>
<linearGradient id="sea" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#d66868"/><stop offset="1" stop-color="#1a2a5c"/></linearGradient>
<radialGradient id="glow" cx="372" cy="188" r="160" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#ffe2a0" stop-opacity="0.8"/><stop offset="1" stop-color="#ffe2a0" stop-opacity="0"/></radialGradient>
<linearGradient id="path" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#ffc882" stop-opacity="0.9"/><stop offset="1" stop-color="#ffc882" stop-opacity="0.1"/></linearGradient>
</defs>
<rect width="600" height="248" fill="url(#sky)"/>
<rect width="600" height="248" fill="url(#glow)"/>
<circle cx="372" cy="188" r="52" fill="#fff0c8"/>
<rect y="248" width="600" height="152" fill="url(#sea)"/>
<path d="M352 248 L392 248 L470 400 L274 400 Z" fill="url(#path)"/>
<path d="M0 248 V170 Q40 150 80 160 Q130 175 170 222 Q200 236 270 248 Z" fill="#30263f"/>
</svg>`;
  return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
}

/** `svg` with the layout's region (and holes) outlined in a dashed line on top, to show where it ends. */
export function outlined(svg: string, layout: Layout, color = "#b4532a"): string {
  const path = `<path d="${regionPath(layout)}" fill="none" stroke="${color}" stroke-width="1.2" stroke-dasharray="4 3" fill-rule="evenodd"/>`;
  return svg.replace(/<\/svg>$/, `${path}</svg>`);
}

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