kitbash Sign in Connect agent
Components

Plate

A full-width black and white landscape painted on a canvas by the part's own script (terrain from the air, haze, a hill cut into stone benches, grain), with the violet band laid over its foot in difference blending. 16:9 on wide screens, a 3:4 crop with a taller band on phones.

Part of the style

Violet Difference

7 parts that belong together, with their tokens, type and rules.

Preview

Code
<style>
/* Goes after the pack's base.css */
:root {
  --paper: #ffffff;
  --ink: #1a49bb;
  --idle: #e7dec6;
  --tray: #f9f6f0;
  --plate: #cebc8b;
  --violet: #82c0fc;
}
</style>

<figure class="plate">
  <span class="plate__frame">
    <canvas class="plate__picture" width="1440" height="810" role="img" aria-label="Black and white view from the air: a wooded hill cut into pale stone benches, two sheds and a chimney on top, hazy ranges behind"
      data-scene='{"seed":7,"blocks":[[0.16,1.42,0.05,0.03,0.035,0],[0.235,1.44,0.014,0.014,0.085,1],[0.3,1.47,0.06,0.03,0.03,0]]}'></canvas>
    <span class="plate__band" aria-hidden="true"></span>
  </span>
</figure>

<style>
  .plate {
    margin: 0;
  }
  .plate__frame {
    position: relative;
    display: block;
    overflow: hidden;
    background: var(--plate);
    isolation: isolate;
  }
  .plate__picture {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    object-position: 66% 50%;
    opacity: 0;
    transition: opacity var(--time-slow) var(--ease);
  }
  .plate__picture.is-painted {
    opacity: 1;
  }

  /* The band is the page's violet laid over the picture and subtracted from it: dark ground stays violet, pale stone turns green. */
  .plate__band {
    position: absolute;
    inset: auto 0 0;
    height: var(--band);
    background: var(--violet);
    mix-blend-mode: difference;
    pointer-events: none;
  }

  @media (max-width: 48rem) {
    .plate__picture {
      aspect-ratio: 3 / 4;
    }
    .plate__band {
      height: calc(2 * var(--band));
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .plate__picture {
      transition-duration: 0s;
    }
  }
</style>

<script>
(() => {
  /* Paints one grey landscape into a canvas: ground seen from the air, drawn column by column from near to far,
     with haze, a hill or pit cut into stone benches, and film grain. The same block sits in every part that shows a picture. */
  function paintPlate(canvas, scene) {
    const W = canvas.width, H = canvas.height;
    const context = canvas.getContext("2d");
    const image = context.createImageData(W, H);
    const s = { seed: 1, eye: 0.62, horizon: 0.3, haze: 0.25, site: [0.25, 1.5, 0.42], dig: 1, cut: 0.5, sea: -1, sun: -1, blocks: [], ...scene };

    let state = Math.imul(s.seed, 2654435761) >>> 0;
    const random = () => (state = (Math.imul(state ^ (state >>> 15), 2246822507) + 0x9e3779b9) >>> 0) / 4294967296;
    const lattice = new Uint8Array(512);
    for (let i = 0; i < 256; i++) lattice[i] = i;
    for (let i = 255; i > 0; i--) { const j = (random() * (i + 1)) | 0, kept = lattice[i]; lattice[i] = lattice[j]; lattice[j] = kept; }
    lattice.copyWithin(256, 0, 256);
    const noise = (x, y) => {
      const xi = Math.floor(x), yi = Math.floor(y);
      let fx = x - xi, fy = y - yi;
      fx *= fx * (3 - 2 * fx); fy *= fy * (3 - 2 * fy);
      const a = lattice[xi & 255], b = lattice[(xi + 1) & 255], lo = yi & 255, hi = (yi + 1) & 255;
      const n00 = lattice[a + lo], n01 = lattice[a + hi], n10 = lattice[b + lo], n11 = lattice[b + hi];
      return (n00 + (n10 - n00) * fx + (n01 - n00) * fy + (n00 - n10 - n01 + n11) * fx * fy) / 255;
    };
    const layered = (x, y, finest) => {
      let sum = 0, gain = 0.5, scale = 1;
      for (let i = 0; i < 9 && 1 / scale > finest; i++) { sum += gain * noise(x * scale + i * 17.3, y * scale - i * 9.1); gain *= 0.5; scale *= 2.03; }
      return sum;
    };
    const ramp = (lo, hi, v) => { const t = Math.min(1, Math.max(0, (v - lo) / (hi - lo))); return t * t * (3 - 2 * t); };

    /* Height and surface tone of the ground at one point. `cell` is the size of one sample there, so far ground gets less detail. */
    const spot = { height: 0, tone: 0, flat: 0 };
    const ground = (x, y, cell) => {
      const dx = x - s.site[0], dy = y - s.site[1];
      const mound = Math.exp(-(dx * dx + dy * dy) / (s.site[2] * s.site[2]));
      const range = ramp(3, 8.5, y);
      let height = layered(x * 1.1, y * 1.1, cell * 2.2) * 0.36 + s.dig * mound * 0.26 - 0.12 + range * s.eye * (0.35 + 1.5 * noise(x * 0.55 + 3, y * 0.3));
      const farmed = ramp(0.5, 0.62, noise(x * 1.7 + 40, y * 1.7 + 11)) * (1 - ramp(0.2, 0.5, mound)) * (1 - ramp(0, 0.3, range));
      height = height * (1 - 0.72 * farmed) + 0.03 * farmed;
      if (cell < 0.03) height += (1 - farmed) * 0.014 * noise(x * 60, y * 60);
      let tone = 0.1 + 0.14 * noise(x * 3.1, y * 3.1) + (cell < 0.012 ? 0.2 * (noise(x * 150, y * 150) - 0.5) : 0);
      if (farmed > 0.02) {
        const turn = Math.floor(noise(x * 2.3 + 7, y * 2.3) * 5) * 1.3;
        const furrow = cell < 0.006 ? 0.14 * Math.sin((x * Math.cos(turn) + y * Math.sin(turn)) * 190) : 0;
        tone += (0.4 + 0.22 * noise(x * 2.3 + 7, y * 2.3 + 60) + furrow - tone) * ramp(0.02, 0.5, farmed);
      }
      const track = Math.abs(noise(x * 0.9 + 80, y * 0.9 + 5) - 0.5);
      if (track < 0.006 + cell * 0.4) tone += (0.7 - tone) * 0.8 * (1 - ramp(1.8, 3.2, y));
      const worked = ramp(1 - s.cut, 1.12 - s.cut, mound + 0.25 * noise(x * 4, y * 4));
      if (worked > 0) {
        const bench = 0.03, level = height / bench, tread = Math.floor(level) + ramp(0.72, 1, level - Math.floor(level));
        height += (tread * bench - height) * worked;
        tone += (0.78 + 0.2 * noise(x * 30, y * 6) - tone) * worked;
      }
      spot.flat = 0;
      if (height < s.sea) { height = s.sea; tone = 0.6 + 0.2 * noise(x * 9, y * 40); spot.flat = 1; }
      for (const [left, front, wide, deep, tall, pale] of s.blocks) {
        const u = (x - left) / wide, v = (y - front) / deep;
        if (u > 0 && u < 1 && v > 0 && v < 1) { height += tall; tone = pale || v < 0.45 ? 1 : 0.25; spot.flat = 1; }
      }
      spot.height = height; spot.tone = tone;
    };

    const focal = H * 1.25, horizon = H * s.horizon, spread = 1.15 * W / H * 0.5625, depths = 460, reach = 9;
    const nearest = Math.max(0.1, (s.eye - 0.4) * focal / (H - horizon));
    const depth = Float32Array.from({ length: depths }, (_, k) => nearest * Math.pow(reach / nearest, k / (depths - 1)));
    const heights = new Float32Array(depths * W), tones = new Float32Array(depths * W), flats = new Uint8Array(depths * W);
    for (let k = 0; k < depths; k++) {
      const cell = depth[k] * spread / W;
      for (let c = 0; c < W; c++) {
        ground((c / W - 0.5) * depth[k] * spread, depth[k], cell);
        heights[k * W + c] = spot.height; tones[k * W + c] = spot.tone; flats[k * W + c] = spot.flat;
      }
    }

    const grey = new Float32Array(W * H), mist = 0.86;
    for (let c = 0; c < W; c++) {
      let floor = H, below = -1;
      for (let k = 1; k < depths - 1 && floor > 0; k++) {
        const i = k * W + c;
        const row = Math.max(0, Math.floor(horizon + (s.eye - heights[i]) * focal / depth[k]));
        if (row >= floor) continue;
        const slopeAcross = (heights[i + (c < W - 1)] - heights[i - (c > 0)]) / (2 * depth[k] * spread / W);
        const slopeAway = (heights[i + W] - heights[i - W]) / (depth[k + 1] - depth[k - 1]);
        const facing = (0.5 + s.sun * 0.8 * slopeAcross - 0.55 * slopeAway) / Math.sqrt(1 + slopeAcross * slopeAcross + slopeAway * slopeAway);
        const lit = tones[i] * (flats[i] ? 1 : 0.3 + 1.25 * Math.max(0, facing));
        const value = lit + (mist - 0.07 - lit) * (1 - Math.exp(-Math.pow(depth[k] * s.haze, 1.25)));
        for (let r = floor - 1; r >= row; r--) grey[r * W + c] = below < 0 ? value : below + (value - below) * (floor - r) / (floor - row);
        floor = row; below = value;
      }
      for (let r = 0; r < floor; r++) {
        const up = Math.max(0, 1 - r / (horizon + H * 0.14));
        const cloud = layered(c / W * 2.6 * spread + 9, up * 7 + s.seed, 0.01) - 0.5;
        grey[r * W + c] = mist - 0.3 * up + 0.36 * cloud * ramp(0.03, 0.45, up);
      }
    }
    for (let i = 0; i < W * H; i++) {
      const corner = Math.hypot((i % W) / W - 0.5, ((i / W) | 0) / H - 0.5);
      let v = Math.min(1, Math.max(0, grey[i] * 1.12 - 0.05));
      v = (0.75 * v * v * (3 - 2 * v) + 0.25 * v) * (1 - 0.5 * corner * corner * corner) + (random() - 0.5) * 0.075;
      image.data[i * 4] = image.data[i * 4 + 1] = image.data[i * 4 + 2] = 255 * v;
      image.data[i * 4 + 3] = 255;
    }
    context.putImageData(image, 0, 0);
    canvas.classList.add("is-painted");
  }

  /* Pictures are painted one per task, so a page full of them never blocks for long. */
  function paintInTurn(canvases) {
    const waiting = [...canvases];
    const next = () => {
      const canvas = waiting.shift();
      if (!canvas) return;
      paintPlate(canvas, JSON.parse(canvas.dataset.scene || "{}"));
      setTimeout(next, 0);
    };
    next();
  }

  document.querySelectorAll(".plate").forEach((root) => paintInTurn(root.querySelectorAll(".plate__picture")));
})();
</script>

Similar components

Film player

Film player

Orbit rings

Orbit rings

Film reel

Film reel

Discipline ticker and machine reel

Discipline ticker and machine reel

Showcase with progress tabs

Showcase with progress tabs

Colour specimen

Colour specimen

About

About

Corner masthead

Corner masthead