All effectsVisual styles

Topographic Isoline Art

地形等值线图案

Contour lines connect locations with equal sampled height, exposing hills, slopes, and saddle points as nested curves.

Adjust the slider to inspect the effect

Where to use it

Build map-like artwork for an editorial background, signage, or an elevation graphic. Keep the lines sparse behind labels. If they communicate measured elevation, use a real height field and show the interval.

Practical example

A trail guide draws contours every 20 meters beside a route map. Hikers can see where the lines bunch together before a pass and anticipate a steeper climb.

AI prompt

Design topographic line art for [surface]. Sample a height field and solve marching-squares intersections by interpolating along each edge. Resolve ambiguous saddle cells consistently. Vary stroke emphasis by level and let density change while keeping foreground labels legible.

Example code

Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.

View HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Topographic Isoline Art</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    .specimen {
      display: grid;
      width: min(100%, 356px);
      gap: 8px;
      margin: 0;
      justify-items: center;
    }
    .specimen canvas {
      display: block;
      width: 100%;
      aspect-ratio: 2;
      max-height: max(72px, calc(100vh - 65px));
      border-radius: 11px;
      background: linear-gradient(145deg, #232943, #14172c);
      box-shadow: 0 8px 22px #090a16a8;
    }
    .specimen label {
      display: grid;
      width: 100%;
      min-height: 25px;
      grid-template-columns: minmax(0, auto) minmax(56px, 1fr);
      align-items: center;
      gap: 8px;
      color: var(--demo-ink);
      font-size: 12px;
    }
    .specimen input {
      width: 100%;
      margin: 0;
      accent-color: #b9a6ff;
    }
    @media (prefers-reduced-motion: reduce) {
      .specimen [data-loop-toggle] { display: none; }
    }
  </style>
</head>
<body>
  <main class="demo">
    <figure class="specimen">
      <canvas role="img" aria-label="Topographic Isoline Art" width="288" height="144">Topographic Isoline Art</canvas>
      <label for="specimen-setting">Line density<input id="specimen-setting" type="range" min="0" max="100" value="52"></label>
    </figure>
  </main>
  <script>
    (() => {
      const canvas = document.querySelector('.specimen canvas');
      const ctx = canvas.getContext('2d');
      if (!ctx) {
        document.querySelector('.specimen :is(input, button)').disabled = true;
        return;
      }
      const width = 288;
      const height = 144;
      const turn = Math.PI * 2;
      let elapsed = 0;
      let variation = 0.52;

      function dot(x, y, radius, ink) {
        ctx.fillStyle = ink;
        ctx.beginPath();
        ctx.arc(x, y, radius, 0, turn);
        ctx.fill();
      }

      function mix(a, b, amount) {
        return a + (b - a) * amount;
      }


      const cell = 4;
      const columns = width / cell;
      const rows = height / cell;
      function elevation(x, y) {
        function bump(cx, cy, spreadX, spreadY, strength) {
          return strength * Math.exp(-(((x - cx) / spreadX) ** 2 + ((y - cy) / spreadY) ** 2));
        }
        return bump(79, 49, 53, 35, 1) + bump(205, 91, 54, 39, 1.12) + bump(171, 37, 40, 30, .34) - bump(144, 78, 32, 25, .35) + .036 * Math.cos(x * .12 + y * .069);
      }
      const samples = Array.from({ length: rows + 1 }, (_, row) =>
        Array.from({ length: columns + 1 }, (_, column) => elevation(column * cell, row * cell))
      );
      const edges = [[0, 1], [1, 2], [2, 3], [3, 0]];

      function draw(_time, amount) {
        const dusk = ctx.createLinearGradient(0, 0, width, height);
        dusk.addColorStop(0, '#27414c');
        dusk.addColorStop(.6, '#1e293d');
        dusk.addColorStop(1, '#292745');
        ctx.fillStyle = dusk;
        ctx.fillRect(0, 0, width, height);
        const levels = Math.round(5 + amount * 20);
        for (let index = 1; index <= levels; index++) {
          const level = index / (levels + 1) * 1.19;
          ctx.lineWidth = index % 4 === 0 ? 1.1 : .63;
          ctx.strokeStyle = index % 4 === 0 ? '#f7d6a9cc' : '#b6dcf08c';
          ctx.beginPath();
          for (let row = 0; row < rows; row++) {
            for (let column = 0; column < columns; column++) {
              const x = column * cell;
              const y = row * cell;
              const corners = [[x, y], [x + cell, y], [x + cell, y + cell], [x, y + cell]];
              const values = [samples[row][column], samples[row][column + 1], samples[row + 1][column + 1], samples[row + 1][column]];
              const crossings = [];
              for (const [start, end] of edges) {
                if ((values[start] >= level) === (values[end] >= level)) continue;
                const factor = (level - values[start]) / (values[end] - values[start]);
                crossings.push([
                  mix(corners[start][0], corners[end][0], factor),
                  mix(corners[start][1], corners[end][1], factor),
                ]);
              }
              if (crossings.length === 2) {
                ctx.moveTo(...crossings[0]);
                ctx.lineTo(...crossings[1]);
              } else if (crossings.length === 4) {
                const centerAbove = values.reduce((sum, value) => sum + value, 0) / 4 >= level;
                const adjacent = centerAbove === (values[0] >= level);
                ctx.moveTo(...crossings[0]);
                ctx.lineTo(...crossings[adjacent ? 1 : 3]);
                ctx.moveTo(...crossings[2]);
                ctx.lineTo(...crossings[adjacent ? 3 : 1]);
              }
            }
          }
          ctx.stroke();
        }
      }

      function render() {
        const ratio = Math.min(devicePixelRatio || 1, 2);
        const pixelsWide = Math.max(1, Math.round(canvas.clientWidth * ratio));
        const pixelsTall = Math.max(1, Math.round(canvas.clientHeight * ratio));
        if (canvas.width !== pixelsWide || canvas.height !== pixelsTall) {
          canvas.width = pixelsWide;
          canvas.height = pixelsTall;
        }
        ctx.setTransform(pixelsWide / width, 0, 0, pixelsTall / height, 0, 0);
        ctx.clearRect(0, 0, width, height);
        ctx.save();
        draw(elapsed, variation);
        ctx.restore();
      }

      render();
      new ResizeObserver(render).observe(canvas);

      const input = document.querySelector('#specimen-setting');
      input.addEventListener('input', () => {
        variation = Number(input.value) / 100;
        render();
      });
    })();
  </script>
</body>
</html>

Original example by UI Skills

Further examples