kitbash Sign in Connect agent
Components

Dot-matrix tally

Big career numbers drawn in dots on canvas that light up left to right when seen, each with a tracked mono label.

Part of the style

Gold Foil Card Wall

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

Preview

Code
<style>
/* Goes after the pack's base.css */
:root {
  --night: #251a1a;
  --night-deep: #1a1010;
  --cream: #fbf4ee;
  --stone: #d6cfc8;
  --ink: #251a1a;
  --ink-soft: #b6afa8;
  --ink-dim: rgba(251, 244, 238, 0.55);
  --line: rgba(251, 244, 238, 0.12);
  --line-ink: rgba(37, 26, 26, 0.14);
  --gold: #a07b75;
  --gold-light: #b59893;
  --gold-dark: #3c2623;
  --violet: #87645e;
  --violet-deep: #5a3b36;
  --violet-haze: #988c89;
}
</style>

<section class="tally" aria-labelledby="tally-title">
  <header class="tally__head">
    <p class="tally__kicker">Career tally <span>·</span> 2021–2026</p>
    <h2 class="tally__title" id="tally-title">Five seasons, counted in dots.</h2>
  </header>

  <ul class="tally__grid">
    <li class="tally__stat">
      <canvas class="tally__canvas" aria-hidden="true"></canvas>
      <span class="tally__value">41</span>
      <p class="tally__label">Starts</p>
      <p class="tally__note">Every one of them on turf, eleven on heavy ground.</p>
    </li>
    <li class="tally__stat">
      <canvas class="tally__canvas" aria-hidden="true"></canvas>
      <span class="tally__value">27</span>
      <p class="tally__label">Wins</p>
      <p class="tally__note">Nine in a row through the summer of the long stretch.</p>
    </li>
    <li class="tally__stat">
      <canvas class="tally__canvas" aria-hidden="true"></canvas>
      <span class="tally__value">12</span>
      <p class="tally__label">Stakes races</p>
      <p class="tally__note">Four of them won from last place at the turn.</p>
    </li>
  </ul>
</section>

<style>
  .tally {
    padding: var(--section-space) var(--edge);
    background: var(--night-deep);
    color: var(--cream);
  }
  .tally__head {
    display: grid;
    gap: var(--space-s);
    margin-bottom: var(--space-xl);
  }
  .tally__kicker {
    margin: 0;
    font: 400 var(--caption)/1.5 var(--font-mono);
    letter-spacing: var(--track-caption);
    text-transform: uppercase;
    color: var(--ink-soft);
  }
  .tally__kicker span { color: var(--gold); }
  .tally__title {
    max-width: 18ch;
    margin: 0;
    font: 800 var(--text-xl)/1.05 var(--font-body);
    letter-spacing: -0.015em;
  }
  .tally__grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--gap);
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .tally__stat {
    display: grid;
    gap: var(--space-xs);
    padding-top: var(--space-m);
    border-top: var(--rule) solid var(--line);
  }
  .tally__canvas {
    width: 100%;
    aspect-ratio: 1.15;
    color: var(--stone);
    font-family: var(--font-display);
  }
  .tally__value {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .tally__label {
    margin: var(--space-m) 0 0;
    font: 500 var(--caption-l)/1.3 var(--font-mono);
    letter-spacing: var(--track-caption);
    text-transform: uppercase;
  }
  .tally__note {
    max-width: 30ch;
    margin: 0;
    font-size: var(--text-s);
    color: var(--ink-dim);
  }

  @media (max-width: 44rem) {
    .tally__grid { grid-template-columns: 1fr; gap: var(--space-l); }
    .tally__canvas { aspect-ratio: 1.6; }
  }
</style>

<script>
(() => {
  const still = matchMedia('(prefers-reduced-motion: reduce)');
  const CELL = 11;
  const SAMPLE = 4;

  /* Read the glyph coverage of each cell once per size. */
  function sample(canvas, text) {
    const width = canvas.clientWidth;
    const height = canvas.clientHeight;
    const cols = Math.max(4, Math.floor(width / CELL));
    const rows = Math.max(4, Math.floor(height / CELL));
    const off = document.createElement('canvas');
    off.width = cols * SAMPLE;
    off.height = rows * SAMPLE;
    const ctx = off.getContext('2d');
    const family = getComputedStyle(canvas).fontFamily;
    let size = off.height * 1.12;
    ctx.font = `400 ${size}px ${family}`;
    const measured = ctx.measureText(text).width;
    if (measured > off.width * 0.98) { size *= (off.width * 0.98) / measured; ctx.font = `400 ${size}px ${family}`; }
    ctx.textBaseline = 'alphabetic';
    ctx.fillStyle = '#fff';
    ctx.fillText(text, 0, off.height * 0.5 + size * 0.42);
    const data = ctx.getImageData(0, 0, off.width, off.height).data;
    const cells = [];
    for (let row = 0; row < rows; row++) {
      for (let col = 0; col < cols; col++) {
        let sum = 0;
        for (let y = 0; y < SAMPLE; y++) {
          for (let x = 0; x < SAMPLE; x++) {
            sum += data[((row * SAMPLE + y) * off.width + col * SAMPLE + x) * 4 + 3];
          }
        }
        cells.push({ col, row, cover: sum / (SAMPLE * SAMPLE * 255), seed: Math.random() * 6.28 });
      }
    }
    return { cols, rows, cells, width, height };
  }

  function paint(context, grid, seconds, color) {
    const { cols, cells, width, height } = grid;
    context.clearRect(0, 0, width, height);
    context.fillStyle = color;
    const sweep = Math.min(1, seconds / 1.4) * (cols + 6);
    for (const cell of cells) {
      const cx = cell.col * CELL + CELL / 2;
      const cy = cell.row * CELL + CELL / 2;
      const lit = cell.col < sweep - (cell.seed % 1) * 6;
      let alpha = 0.07;
      let radius = 1.1;
      if (cell.cover > 0.08 && lit) {
        const shimmer = seconds > 1.4 ? 0.82 + 0.18 * Math.sin(seconds * 1.6 + cell.seed) : 1;
        alpha = Math.min(1, 0.35 + cell.cover) * shimmer;
        radius = 1.3 + cell.cover * (CELL * 0.26);
      }
      context.globalAlpha = alpha;
      context.beginPath();
      context.arc(cx, cy, radius, 0, Math.PI * 2);
      context.fill();
    }
    context.globalAlpha = 1;
  }

  function run(stat) {
    const canvas = stat.querySelector('.tally__canvas');
    const text = stat.querySelector('.tally__value').textContent.trim();
    const context = canvas.getContext('2d');
    let grid = null;
    let frame = 0;
    let start = null;
    const color = () => getComputedStyle(canvas).color;
    const draw = (now) => {
      if (!grid) return;
      /* Before the first view the numbers stand complete, so a still of the page is never blank. */
      const seconds = still.matches || start === null ? 10 : (now - start) / 1000;
      paint(context, grid, seconds, color());
    };
    const fit = () => {
      const density = Math.min(2, devicePixelRatio || 1);
      canvas.width = canvas.clientWidth * density;
      canvas.height = canvas.clientHeight * density;
      context.setTransform(density, 0, 0, density, 0, 0);
      grid = sample(canvas, text);
      draw(performance.now());
    };
    const tick = (now) => {
      draw(now);
      frame = requestAnimationFrame(tick);
    };
    document.fonts.load(`400 100px ${getComputedStyle(canvas).fontFamily}`).catch(() => {}).then(() => {
      new ResizeObserver(fit).observe(canvas);
      new IntersectionObserver(([entry]) => {
        cancelAnimationFrame(frame);
        if (entry.isIntersecting && !still.matches) {
          if (start === null) start = performance.now();
          frame = requestAnimationFrame(tick);
        }
        else draw(performance.now());
      }).observe(canvas);
    });
  }

  document.querySelectorAll('.tally__stat').forEach(run);
})();
</script>

Similar components

Avatar stack and name grid

Avatar stack and name grid

Logo cells and counts

Logo cells and counts

Countdown block

Countdown block

Holding sheet

Holding sheet

Wireframe and system status

Wireframe and system status

Speckled result figure

Speckled result figure

Rolling number row

Rolling number row

Numbers

Numbers