Scanline lettering
Hero with two words drawn on canvas from a seven-row bar alphabet: a thin, still word behind and a front word whose bars swell and sink into it, with rows that slip sideways at random and smear under the pointer. Registration blocks on the page edges, a meta line with a live slip counter. The words are read from the heading, which stays in the page for screen readers.
Part of the style
Scanline Red
7 parts that belong together, with their tokens, type and rules.
https://kitbash.me/components/scanline-red/signal/figma.html?type=hostile-hud
Use the Figma MCP server (https://mcp.figma.com/mcp). Download https://kitbash.me/components/scanline-red/signal/figma.html?type=hostile-hud and pass that whole HTML document to the html_to_figma tool, so the part "Scanline lettering" lands as editable layers in my open Figma file. Fonts come from Google Fonts: if a face is missing in Figma, pick the closest one.
Code
<style>
/* Goes after the pack's base.css */
@import url("https://fonts.googleapis.com/css2?family=Barlow+Semi+Condensed:wght@400;500&family=JetBrains+Mono:wght@400;500&display=swap");
:root {
--font-text: "Barlow Semi Condensed", "Arial Narrow", sans-serif;
--font-scan: "JetBrains Mono", ui-monospace, monospace;
--font-pixel: "JetBrains Mono", ui-monospace, monospace;
}
</style>
<header class="signal">
<div class="signal__stage">
<h1 class="signal__title">
<span class="signal__word signal__word--front">Static</span>
<span class="signal__word signal__word--back">Almanac</span>
</h1>
<canvas class="signal__canvas" aria-hidden="true"></canvas>
<span class="signal__frame" aria-hidden="true"></span>
</div>
<p class="signal__meta">
<span class="signal__issue">Vol. 07 / Winter log</span>
<span class="signal__slips" aria-hidden="true">Line slips <span class="signal__count">000</span></span>
</p>
</header>
<style>
.signal {
position: relative;
overflow: hidden;
padding-block: clamp(3.5rem, 9vw, 6.5rem) clamp(2rem, 5vw, 3.5rem);
background: var(--red);
color: var(--dark);
}
/* Registration blocks on both page edges: two per side, drawn as backgrounds so they need no markup. */
.signal::before,
.signal::after {
content: "";
position: absolute;
inset-block: 0;
width: var(--tick-w);
background:
linear-gradient(var(--dark), var(--dark)) 0 9% / 100% var(--tick-1) no-repeat,
linear-gradient(var(--dark), var(--dark)) 0 55% / 100% var(--tick-2) no-repeat;
pointer-events: none;
}
.signal::before {
left: 0;
}
.signal::after {
right: 0;
}
.signal__stage {
position: relative;
}
/* Without script the title is plain text in the pixel face. With script it stays for screen readers and the canvas draws it. */
.signal__title {
margin: 0;
padding-inline: var(--edge) var(--gutter);
font-family: var(--font-pixel);
font-size: clamp(1.5rem, 9vw, 5rem);
font-weight: 400;
font-variation-settings: "BLED" var(--bleed-off), "SCAN" var(--scan-thin);
line-height: 1.3;
text-transform: uppercase;
}
.signal__word {
display: block;
}
.signal.is-drawn .signal__title {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
.signal__canvas {
display: none;
width: 100%;
touch-action: pan-y;
}
.signal.is-drawn .signal__canvas {
display: block;
}
/* The box the lettering is fitted into. The script reads its left edge and width, so the layout stays in CSS. */
.signal__frame {
position: absolute;
inset: 0 var(--gutter) 0 var(--edge);
max-width: 72rem;
pointer-events: none;
}
.signal__frame::before,
.signal__frame::after {
content: "";
position: absolute;
left: calc(-1 * var(--step-offset));
width: var(--tick-w);
height: var(--tick-4);
background: var(--dark);
}
.signal__frame::before {
top: 12%;
}
.signal__frame::after {
bottom: -18%;
}
.signal__meta {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
gap: var(--space-xs) var(--space-m);
margin: clamp(2.5rem, 6vw, 4rem) 0 0;
padding-inline: var(--edge) var(--gutter);
font-size: var(--text-s);
line-height: var(--leading-tight);
text-transform: uppercase;
}
.signal__count {
display: inline-block;
padding-inline: 0.35em;
background: var(--dark);
color: var(--red);
font-variant-numeric: tabular-nums;
}
</style>
<script>
(() => {
/* The alphabet: seven scan rows per letter, seven columns wide. Every run of # becomes one bar. */
const GLYPHS = {
A: "..###../.##.##./##...##/##...##/#######/##...##/##...##",
B: "######./##...##/##...##/######./##...##/##...##/######.",
C: ".#####./##...##/##...../##...../##...../##...##/.#####.",
D: "#####../##..##./##...##/##...##/##...##/##..##./#####..",
E: "#######/##...../##...../#####../##...../##...../#######",
F: "#######/##...../##...../#####../##...../##...../##.....",
G: ".#####./##...##/##...../##.####/##...##/##...##/.#####.",
H: "##...##/##...##/##...##/#######/##...##/##...##/##...##",
I: ".#####./..###../..###../..###../..###../..###../.#####.",
J: "...####/.....##/.....##/.....##/##...##/##...##/.#####.",
K: "##...##/##..##./##.##../####.../##.##../##..##./##...##",
L: "##...../##...../##...../##...../##...../##...../#######",
M: "##...##/###.###/#######/##.#.##/##...##/##...##/##...##",
N: "##...##/###..##/####.##/##.####/##..###/##...##/##...##",
O: ".#####./##...##/##...##/##...##/##...##/##...##/.#####.",
P: "######./##...##/##...##/######./##...../##...../##.....",
Q: ".#####./##...##/##...##/##...##/##.#.##/##..##./.###.##",
R: "######./##...##/##...##/######./##.##../##..##./##...##",
S: ".#####./##...##/##...../.#####./.....##/##...##/.#####.",
T: "#######/..###../..###../..###../..###../..###../..###..",
U: "##...##/##...##/##...##/##...##/##...##/##...##/.#####.",
V: "##...##/##...##/##...##/##...##/.##.##./..###../...#...",
W: "##...##/##...##/##...##/##.#.##/#######/###.###/##...##",
X: "##...##/.##.##./..###../..###../..###../.##.##./##...##",
Y: "##...##/##...##/.##.##./..###../..###../..###../..###..",
Z: "#######/....##./...##../..##.../.##..../##...../#######",
0: ".#####./##...##/##..###/##.#.##/###..##/##...##/.#####.",
1: "..###../.####../..###../..###../..###../..###../.#####.",
2: ".#####./##...##/.....##/...###./.###.../##...../#######",
3: ".#####./##...##/.....##/..####./.....##/##...##/.#####.",
4: "...###./..####./.##.##./##..##./#######/....##./....##.",
5: "#######/##...../######./.....##/.....##/##...##/.#####.",
6: ".#####./##...../######./##...##/##...##/##...##/.#####.",
7: "#######/.....##/....##./...##../..##.../..##.../..##...",
8: ".#####./##...##/##...##/.#####./##...##/##...##/.#####.",
9: ".#####./##...##/##...##/.######/.....##/.....##/.#####.",
"-": "......./......./......./.#####./......./......./.......",
" ": "......./......./......./......./......./......./.......",
};
const GLYPH_ROWS = 7;
const GLYPH_ADVANCE = 8;
const UNKNOWN_GLYPH = "-";
/* The stage, measured in rows. The back word sits still, the front word travels down into it. */
const STAGE_ROWS = 16;
const FRONT_TOP_ROW = 0.6;
const FRONT_TRAVEL_ROWS = 2.4;
const BACK_TOP_ROW = 8;
const MAX_ROW_PX = 22;
/* Bar weights as a share of one row. */
const BACK_WEIGHT = 0.24;
const FRONT_WEIGHT_THIN = 0.2;
const FRONT_WEIGHT_FULL = 0.8;
const HALO_WEIGHT = 0.3;
const INK_BLEED = 0.22;
const BREATH_START = 0.19;
const STILL_BREATH = 0.7;
/* Line slips: a band of rows jumps sideways. Short ones flicker, long ones hold and snap back. */
const FRAME_MS = 33;
const FIRST_SLIP = { firstRow: 4, rows: 2, shift: 1.5, holdMs: 1500, flickers: false, delayMs: 900 };
const SLIP_GAP_MS = [1300, 4200];
const FLICKER_MS = [120, 320];
const HOLD_MS = [700, 1500];
const SLIP_SHIFT = [0.8, 3.6];
const FLICKER_STEP_MS = 70;
const HOLD_CHANCE = 0.4;
/* Dragging the pointer across the lettering smears the rows under it. */
const PULL_GAIN = 0.07;
const PULL_LIMIT = 4;
const PULL_DECAY = 0.86;
const between = ([low, high]) => low + Math.random() * (high - low);
const barsOfGlyph = (pattern, column) =>
pattern.split("/").flatMap((row, rowIndex) =>
[...row.matchAll(/#+/g)].map((run) => ({
row: rowIndex,
from: column + run.index,
to: column + run.index + run[0].length,
})),
);
const layoutWord = (text) => {
const letters = [...text.trim().toUpperCase()];
return {
columns: letters.length * GLYPH_ADVANCE - 1,
bars: letters.flatMap((letter, index) => barsOfGlyph(GLYPHS[letter] || GLYPHS[UNKNOWN_GLYPH], index * GLYPH_ADVANCE)),
};
};
const breathAt = (seconds, cycle) => 0.5 - 0.5 * Math.cos(2 * Math.PI * (seconds / cycle + BREATH_START));
const newSlip = (now) => {
const holds = Math.random() < HOLD_CHANCE;
const rows = 1 + Math.floor(Math.random() * 3);
return {
firstRow: Math.floor(Math.random() * (STAGE_ROWS - rows)),
rows,
shift: between(SLIP_SHIFT) * (Math.random() < 0.5 ? -1 : 1),
until: now + between(holds ? HOLD_MS : FLICKER_MS),
flickers: !holds,
};
};
const slipShiftAt = (slip, row, now) => {
if (row < slip.firstRow || row >= slip.firstRow + slip.rows) return 0;
if (!slip.flickers) return slip.shift;
return Math.floor(now / FLICKER_STEP_MS) % 2 ? slip.shift : slip.shift * -0.4;
};
const setUpSignal = (root) => {
const canvas = root.querySelector(".signal__canvas");
const frame = root.querySelector(".signal__frame");
const counter = root.querySelector(".signal__count");
const context = canvas.getContext("2d");
const tokens = getComputedStyle(root);
const ink = tokens.getPropertyValue("--dark").trim();
const paper = tokens.getPropertyValue("--red").trim();
const cycleSeconds = parseFloat(tokens.getPropertyValue("--cycle")) || 24;
const front = layoutWord(root.querySelector(".signal__word--front").textContent);
const back = layoutWord(root.querySelector(".signal__word--back").textContent);
const widestColumns = Math.max(front.columns, back.columns);
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)");
const pull = new Float32Array(STAGE_ROWS);
let rowPx = 0;
let originX = 0;
let pixelRatio = 1;
let slips = [];
let slipCount = 0;
let nextSlipAt = 0;
let startedAt = 0;
let lastFrameAt = 0;
let frameRequest = 0;
let onScreen = false;
const measure = () => {
rowPx = Math.min(frame.offsetWidth / widestColumns, MAX_ROW_PX);
originX = frame.offsetLeft;
pixelRatio = Math.min(window.devicePixelRatio || 1, 2);
canvas.style.height = `${STAGE_ROWS * rowPx}px`;
canvas.width = Math.round(canvas.clientWidth * pixelRatio);
canvas.height = Math.round(STAGE_ROWS * rowPx * pixelRatio);
};
const shiftOfRow = (row, now) => {
const slipped = slips.reduce((sum, slip) => sum + slipShiftAt(slip, row, now), 0);
return (slipped + (pull[row] || 0)) * rowPx;
};
const traceWord = (word, left, topRow, weight, now) => {
context.beginPath();
word.bars.forEach((bar) => {
const stageRow = topRow + bar.row;
const y = (stageRow + 0.5) * rowPx;
const shift = shiftOfRow(Math.floor(stageRow + 0.5), now);
const start = left + bar.from * rowPx + weight / 2 + shift;
const end = left + bar.to * rowPx - weight / 2 + shift;
context.moveTo(start, y);
context.lineTo(Math.max(end, start + 0.01), y);
});
};
const paint = (breath, now) => {
const frontWeight = (FRONT_WEIGHT_THIN + (FRONT_WEIGHT_FULL - FRONT_WEIGHT_THIN) * breath) * rowPx;
const frontLeft = originX + ((back.columns - front.columns) / 2) * rowPx;
context.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
context.clearRect(0, 0, canvas.width, canvas.height);
context.lineCap = "round";
context.shadowBlur = 0;
context.strokeStyle = ink;
context.lineWidth = BACK_WEIGHT * rowPx;
traceWord(back, originX, BACK_TOP_ROW, BACK_WEIGHT * rowPx, now);
context.stroke();
/* The front word is stroked twice: first in the page colour, wider, to burn a halo through the back word, then in ink. */
traceWord(front, frontLeft, FRONT_TOP_ROW + FRONT_TRAVEL_ROWS * breath, frontWeight, now);
context.strokeStyle = paper;
context.shadowColor = paper;
context.shadowBlur = HALO_WEIGHT * rowPx * pixelRatio;
context.lineWidth = frontWeight + HALO_WEIGHT * rowPx;
context.stroke();
context.strokeStyle = ink;
context.shadowColor = ink;
context.shadowBlur = INK_BLEED * rowPx * pixelRatio;
context.lineWidth = frontWeight;
context.stroke();
};
const paintStill = () => {
slips = [];
pull.fill(0);
paint(STILL_BREATH, 0);
};
const startSlip = (slip) => {
slips.push(slip);
slipCount += 1;
counter.textContent = String(slipCount % 1000).padStart(3, "0");
};
const updateSlips = (now) => {
slips = slips.filter((slip) => slip.until > now);
if (now < nextSlipAt) return;
startSlip(slipCount ? newSlip(now) : { ...FIRST_SLIP, until: now + FIRST_SLIP.holdMs });
nextSlipAt = now + between(SLIP_GAP_MS);
};
const relaxPull = () => {
pull.forEach((value, row) => {
pull[row] = value * PULL_DECAY;
});
};
const tick = (now) => {
frameRequest = requestAnimationFrame(tick);
if (now - lastFrameAt < FRAME_MS) return;
lastFrameAt = now;
updateSlips(now);
relaxPull();
paint(breathAt((now - startedAt) / 1000, cycleSeconds), now);
};
const stop = () => {
cancelAnimationFrame(frameRequest);
frameRequest = 0;
};
const run = () => {
stop();
if (reducedMotion.matches) {
paintStill();
return;
}
if (!onScreen) return;
startedAt = startedAt || performance.now();
nextSlipAt = nextSlipAt || startedAt + FIRST_SLIP.delayMs;
frameRequest = requestAnimationFrame(tick);
};
const smear = (event) => {
if (reducedMotion.matches || !rowPx) return;
const row = Math.floor((event.clientY - canvas.getBoundingClientRect().top) / rowPx);
[row - 1, row, row + 1].forEach((nearRow, index) => {
if (nearRow < 0 || nearRow >= STAGE_ROWS) return;
const gain = index === 1 ? PULL_GAIN : PULL_GAIN / 2;
pull[nearRow] = Math.max(-PULL_LIMIT, Math.min(PULL_LIMIT, pull[nearRow] + event.movementX * gain));
});
};
root.classList.add("is-drawn");
measure();
paintStill();
new ResizeObserver(() => {
measure();
if (frameRequest) return;
paintStill();
}).observe(root);
new IntersectionObserver(([entry]) => {
onScreen = entry.isIntersecting;
run();
}).observe(root);
reducedMotion.addEventListener("change", run);
canvas.addEventListener("pointermove", smear);
};
document.querySelectorAll(".signal").forEach(setUpSignal);
})();
</script>