Craft / Animation
World Clock Board
Show three world clocks in fixed LED blocks, then shuffle each city name when its time changes.
Demo
InteractiveCopy this component. Each row has five separate blocks for HH:MM, a clear gap, and 15 separate blocks for the city. The 5×7 letter patterns live in the file, so there is no font or extra stylesheet to load. City names longer than 15 characters are clipped to fit.
"use client";
import { useEffect, useRef, useState } from "react";
const FONT: Record<string, string> = {
" ": "00000000000000000000000000000000000",
"0": "01110100011001110101110011000101110",
"1": "00100011000010000100001000010001110",
"2": "01110100010000100010001000100011111",
"3": "11110000010000101110000010000111110",
"4": "00010001100101010010111110001000010",
"5": "11111100001000011110000010000111110",
"6": "00110010001000011110100011000101110",
"7": "11111000010001000100010000100001000",
"8": "01110100011000101110100011000101110",
"9": "01110100011000101111000010001001100",
":": "00000001000010000000001000010000000",
A: "01110100011000111111100011000110001",
B: "11110100011000111110100011000111110",
C: "01110100011000010000100001000101110",
D: "11110100011000110001100011000111110",
E: "11111100001000011110100001000011111",
F: "11111100001000011110100001000010000",
G: "01110100011000010111100011000101111",
H: "10001100011000111111100011000110001",
I: "01110001000010000100001000010001110",
J: "00111000100001000010000101001001100",
K: "10001100101010011000101001001010001",
L: "10000100001000010000100001000011111",
M: "10001110111010110101100011000110001",
N: "10001110011010110011100011000110001",
O: "01110100011000110001100011000101110",
P: "11110100011000111110100001000010000",
Q: "01110100011000110001101011001001101",
R: "11110100011000111110101001001010001",
S: "01111100001000001110000010000111110",
T: "11111001000010000100001000010000100",
U: "10001100011000110001100011000101110",
V: "10001100011000110001010100010000100",
W: "10001100011000110101101011010101010",
X: "10001100010101000100010101000110001",
Y: "10001100010101000100001000010000100",
Z: "11111000010001000100010001000011111",
};
const CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
const CELL_W = 5;
const CELL_H = 7;
const TIME_SLOTS = 5;
const CITY_SLOTS = 15;
const HOLD_MS = 320;
const DEFAULT_CITIES = [
{ name: "NEW YORK CITY", timeZone: "America/New_York" },
{ name: "TOKYO", timeZone: "Asia/Tokyo" },
{ name: "NEW DELHI", timeZone: "Asia/Kolkata" },
];
type City = {
name: string;
timeZone: string;
};
type WorldClockBoardProps = {
cities?: City[];
staggerMs?: number;
cycleMs?: number;
replay?: number;
announce?: boolean;
className?: string;
};
function formatTime(timeZone: string, date: Date) {
const parts = new Intl.DateTimeFormat("en-GB", {
timeZone,
hour: "2-digit",
minute: "2-digit",
hourCycle: "h23",
}).formatToParts(date);
const hour = parts.find((part) => part.type === "hour")?.value ?? "00";
const minute = parts.find((part) => part.type === "minute")?.value ?? "00";
return `${hour.slice(-2).padStart(2, "0")}:${minute.slice(-2).padStart(2, "0")}`;
}
function clockLines(cities: City[], date: Date | null) {
return cities.map((city) => {
const time = date ? formatTime(city.timeZone, date) : " ".repeat(TIME_SLOTS);
const name = (city.name.trim().toUpperCase() || "CITY").slice(0, CITY_SLOTS);
return `${time}${name.padEnd(CITY_SLOTS, " ")}`;
});
}
function lit(glyph: string, x: number, y: number) {
return glyph[y * CELL_W + x] === "1";
}
function LedGlyph({ glyph }: { glyph: string }) {
return (
<svg viewBox={`0 0 ${CELL_W} ${CELL_H}`} className="block w-full" focusable="false">
{Array.from({ length: CELL_W * CELL_H }, (_, dot) => {
const x = dot % CELL_W;
const y = Math.floor(dot / CELL_W);
return (
<circle
key={dot}
cx={x + 0.5}
cy={y + 0.5}
r={0.38}
className={lit(glyph, x, y) ? "fill-[#f2f2f2]" : "fill-[#434343]"}
/>
);
})}
</svg>
);
}
function LedMatrix({ lines }: { lines: string[] }) {
return (
<div
className="grid w-full gap-y-[clamp(14px,2.4cqi,28px)]"
>
{lines.map((line, rowIndex) => (
<div
key={rowIndex}
className="grid items-start gap-x-[clamp(4px,0.7cqi,8px)]"
style={{ gridTemplateColumns: `repeat(${TIME_SLOTS}, minmax(0, 1fr)) minmax(0, 1fr) repeat(${CITY_SLOTS}, minmax(0, 1fr))` }}
>
{[...line].map((character, column) => (
<div
key={column}
style={column === TIME_SLOTS ? { gridColumn: column + 2 } : undefined}
>
<LedGlyph glyph={FONT[character] ?? FONT[" "]} />
</div>
))}
</div>
))}
</div>
);
}
function useFlapRows(rows: string[], staggerMs: number, cycleMs: number, replay: number) {
const signature = rows.join("\n");
const [shown, setShown] = useState(() => rows.map((row) => " ".repeat(row.length)));
const previous = useRef<string[] | null>(null);
const replaySeen = useRef(replay);
useEffect(() => {
const next = signature.length === 0 ? [] : signature.split("\n");
const stagger = Math.min(160, Math.max(12, staggerMs));
const cycle = Math.min(180, Math.max(32, cycleMs));
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const prior = previous.current;
const force = replay !== replaySeen.current;
const dirty = next.map((row, rowIndex) =>
[...row].map((character, column) => {
if (reduce) return false;
if (force || prior === null) return true;
if (column >= TIME_SLOTS && prior[rowIndex]?.slice(0, TIME_SLOTS) !== row.slice(0, TIME_SLOTS)) return true;
return prior[rowIndex]?.[column] !== character;
}),
);
if (!dirty.some((row) => row.some(Boolean))) {
previous.current = next;
replaySeen.current = replay;
setShown(next);
return;
}
const started = performance.now();
let timer = 0;
const paint = () => {
const now = performance.now();
let pending = false;
const frame = next.map((row, rowIndex) => {
let line = "";
for (let column = 0; column < row.length; column += 1) {
const goal = row[column] ?? " ";
const city = column >= TIME_SLOTS;
const position = city ? column - TIME_SLOTS : column;
const last = city ? CITY_SLOTS - 1 : TIME_SLOTS - 1;
const delay = stagger * last * (1 - Math.cos(Math.PI * position / last)) / 2;
if (!dirty[rowIndex]?.[column] || now >= started + delay + HOLD_MS) {
line += goal;
} else if (now < started + delay) {
pending = true;
line += prior?.[rowIndex]?.[column] ?? " ";
} else {
pending = true;
line += CHARSET[Math.floor(Math.random() * CHARSET.length)];
}
}
return line;
});
setShown(frame);
if (!pending) {
previous.current = next;
replaySeen.current = replay;
window.clearInterval(timer);
}
return pending;
};
if (paint()) timer = window.setInterval(paint, cycle);
return () => window.clearInterval(timer);
}, [signature, staggerMs, cycleMs, replay]);
return shown;
}
export function WorldClockBoard({
cities = DEFAULT_CITIES,
staggerMs = 70,
cycleMs = 80,
replay = 0,
announce = true,
className,
}: WorldClockBoardProps) {
const [date, setDate] = useState<Date | null>(null);
useEffect(() => {
const publish = () => {
const next = new Date();
setDate((current) => {
if (current && clockLines(cities, current).join("\n") === clockLines(cities, next).join("\n")) {
return current;
}
return next;
});
};
publish();
const timer = window.setInterval(publish, 1000);
return () => window.clearInterval(timer);
}, [cities]);
const rows = clockLines(cities, date);
const shown = useFlapRows(rows, staggerMs, cycleMs, replay);
const label = date
? rows
.map((row) => `${row.slice(0, TIME_SLOTS)} ${row.slice(TIME_SLOTS).trim()}`)
.filter(Boolean)
.join(". ")
: "";
return (
<div
className={`w-full overflow-hidden rounded-xl border border-white/10 bg-black px-3 py-6 shadow-[inset_0_0_16px_rgba(0,0,0,0.9)] sm:px-5 sm:py-7${className ? ` ${className}` : ""}`}
style={{ containerType: "inline-size" }}
>
<p className="sr-only" aria-live={announce ? "polite" : undefined}>
{label}
</p>
<div aria-hidden="true">
<LedMatrix lines={shown} />
</div>
</div>
);
}Pass cities to change the rows. Each entry needs a label and an IANA time zone, such as America/New_York. staggerMs is the delay between shuffling blocks, and replay is a number you increment to shuffle the board again.
The whole clock grows from one small piece: a tile of 35 lights. Make that tile look like 0, and you know how to make A, :, and every other character too. Thanks to @kayanoesasaki's post for the idea behind this board.
01 / Draw with switches
R4 · C3The same 35 switches, now shown as round LEDs.
02 / Save the drawing
35 BITSRead each row left to right, then move down.
03 / Find one light
17 ÷ 5 = 3 complete rows with 2 left over. This LED is on.
01 — Draw one tiny picture
Look at Draw with switches above. It is graph paper with five squares across and seven down. Each square is a little light switch. Tap a square to turn it on or off. Try turning off the middle square in row 4, then turn it on again. The picture changes immediately.
Each square is an HTML button, so it can be clicked or used with a keyboard. The CSS grid has five switch columns and a narrow space for row numbers. React's useState remembers which lights are on after a tap. The onClick handler replaces just that square's value.
const [glyph, setGlyph] = useState(FONT["0"])
// dot is the square you tapped, numbered 0 through 34.
setGlyph((current) =>
current.slice(0, dot) +
(current[dot] === "1" ? "0" : "1") +
current.slice(dot + 1)
)You made: one editable 5×7 character tile. The buttons are square so you can see its little drawing grid.
02 — Write down the picture
Look at Save the drawing. For every row, write 1 for an on square and 0 for an off square. The number 0 starts like this:
row 1 01110 ·●●●·
row 2 10001 ●···●
row 3 10011 ●··●●
row 4 10101 ●·●·●
row 5 11001 ●●··●
row 6 10001 ●···●
row 7 01110 ·●●●·There are seven rows of five, so there are 35 digits. Put the rows together, top to bottom, and you have one long string. The FONT object saves a string like this under each character's name. Pick A, :, or Blank above: the same 35 lights stay in place, but their on/off recipe changes. Blank has 35 zeros.
const FONT: Record<string, string> = {
"0": "01110100011001110101110011000101110",
A: "01110100011000111111100011000110001",
":": "00000001000010000000001000010000000",
" ": "00000000000000000000000000000000000",
}You made: a tiny picture you can save as text. Try drawing your own letter; the 35-digit string changes with every tap.
03 — Read the recipe to light a dot
Look at the position numbers beside Save the drawing. The string is not cut into pieces. The code reads its characters one after another, starting at position 0, and makes one round LED for each character. The LED grid has five columns. Positions 0 to 4 fill its first row; position 5 starts the next row.
column 1 2 3 4 5
row 1 string index 0 1 2 3 4
row 2 5 6 7 8 9
row 3 10 11 12 13 14
row 4 15 16 17 18 19
row 5 20 21 22 23 24
row 6 25 26 27 28 29
row 7 30 31 32 33 34Find 17 in that grid: it is in row 4, column 3. For our 0 drawing, positions 15 to 19 contain 10101, so position 17 contains 1. The round LED there lights up. If you tap that square above, its digit becomes 0 and that one LED goes dark.
How can the code find a position from a row and column? It counts the five digits in every complete row before this one, then moves across. The labels on the drawing start at 1; code coordinates start at 0. So row 4, column 3 becomes y = 3, x = 2: 3 × 5 + 2 = 17.
function lit(glyph: string, x: number, y: number) {
return glyph[y * 5 + x] === "1"
}The component draws one SVG for the tile. viewBox makes the picture 5 units wide and 7 units tall, one unit per light. Each digit becomes a <circle> in string order. dot % 5 is the column and Math.floor(dot / 5) is the row. Adding 0.5 puts that circle in the middle of its unit square. lit reads the matching digit and chooses a bright or dark fill.
<svg viewBox={`0 0 ${CELL_W} ${CELL_H}`} className="block w-full">
{Array.from({ length: CELL_W * CELL_H }, (_, dot) => {
const x = dot % CELL_W
const y = Math.floor(dot / CELL_W)
return (
<circle
key={dot}
cx={x + 0.5}
cy={y + 0.5}
r={0.38}
className={lit(glyph, x, y) ? "fill-[#f2f2f2]" : "fill-[#434343]"}
/>
)
})}
</svg>You made: a renderer for any 5×7 bitmap letter. Every digit in the string has one fixed place in the grid and controls exactly one round LED.
04 — Use the tile again and again
19:45 New York City. 08:45 Tokyo. 05:15 New Delhi.
The board asks FONT for each character's 35-digit recipe and draws another tile. Five tiles make HH:MM; 15 more make the city field. A space has an all-zero recipe, so unused city tiles stay dark. The gap between time and city is actual empty space between the groups.
The live board briefly swaps characters while a time changes, then settles on the new ones; the bitmap rule never changes. Its timer stops when the animation finishes or the component leaves the page, and reduced-motion settings show the final characters right away. Screen readers receive the clock text instead of trying to read the dot picture.
Check yourself: If you change one 1 to 0 in a letter's recipe, how many LEDs change? Just one.