A toolbox of film styles made in code for Claude Code: 66 ready to use, and your own. Each style is a style prompt plus a demo film made entirely in code by Claude Opus 5.5, with no video model. By Lemomo. · 一套用代码做片的风格工具箱:66 种现成风格,也能做出你自己的
JavaScript agent-skillsai-agentsai-short-filmai-videoanimationcanvasclaudeclaude-codeclaude-code-pluginclaude-code-skillcreative-codingffmpegfilmmakingmotion-graphicsopus-5-5prompt-librarytext-to-speechthreejsvideo-productionwebgl
Circuit Board: the story drawn as a printed circuit board seen from above, current running along the traces, with narration and bilingual subtitles
lemomo-aic8aeccb34c55
diff --git a/styles/circuit-board/DEMO.md b/styles/circuit-board/DEMO.mdnew file mode 100644index 0000000..4104fd8--- /dev/null+++ b/styles/circuit-board/DEMO.md@@ -0,0 +1,66 @@+# Circuit Board — our demo++One example among many. Don't reuse its story, arc, shots, props or timings.++Demo: *Seven Milliseconds · 七毫秒* (60 s, Chinese voice-over, bilingual subtitles) · `circuit-board.mp4` · source in [`demo/`](demo/)++## Story & structure++Power made deep in the mountains of Sichuan reaches Jiangsu, 2,000 km away, in seven milliseconds. A Chinese voice (edge-tts Xiaoxiao, +20%) tells it as a friend would: household power swings back and forth (alternating current); sent that far it would be lost on the way; so a converter station turns it into one-way direct current; it races 2,080 km in 7 ms; at the other end it is turned back, stepped down level by level and sent to a wall socket; inside a phone charger a tiny bridge rectifier does the same job as the giant in the converter station, on the same circuit principle, with 400 million times less power. Every line has a subtitle (Chinese over English, bottom safe area); the board itself only prints the voice's key words and numbers (交流电 / AC, 损耗 / LOSS, 换流站, 直流电, 2,080 公里, 7 毫秒, 降压, 充电器, 整流桥, 同一个电路原理, 功率差 4 亿倍). Facts: [`demo/FACTS.md`](demo/FACTS.md).++Native moves spent: flow becomes current (dam), pulse-path explainer (the whole film), AC vs DC told by the shape of the light (bus close-up, loss board, Butuo), the map is a board (corridor), matched step-down (four cuts), plunge through a hole (socket → charger), detail callout (verdict), nested boards (closing pull-out).++## Shots++| # | Time | Voice (first words) | Shot | Camera | Note |+|---|---|---|---|---|---|+| 1 | 0–4.7 | 四川深山里发出来的电… | Baihetan: water through 16 penstocks, generators light on 16ths; title 七毫秒 / SEVEN MILLISECONDS top right | macro on G1 at frame 0, pull-out ×10 by 2.0 s, hold | flow becomes current |+| 2 | 4.7–10.1 | 平时我们家里用的电… | the right-bank bus close up: big AC dashes swinging slowly back and forth; 交流电 / AC with a silk sine | push in, hold | the swing slowed to ~0.55 Hz |+| 3 | 10.1–14.4 | 如果直接送去太远的地方… | a long straight board: AC dashes move on, dimmer, thinner and fewer; 损耗 / LOSS | slow pan right | stand-alone board |+| 4 | 14.4–19.1 | 所以,电得先进一趟换流站… | Butuo: AC in, the bridge conducts at 16.3, two DC streams out; 交流电, 换流站, 直流电 | slow push, whip east at 18.75 | |+| 5 | 19.1–23.5 | 然后再顺着这根两千多公里长的电线… | the corridor: rides the DC head, rises until both ends are in frame; 四川 / 江苏 large, 2,080 公里 | ride → rise → crash zoom at 23.0 | main line ≥ 6.5 px wide at map scale |+| 6 | 23.5–29.6 | 全程只要七毫秒… / 到了终点站… | Yucheng: 7 毫秒 / 7 ms tag; at 27.4 AC leaves (交流电 / AC) | locked | reading hold |+| 7 | 29.6–32.4 | …再把电压一级一级降下来… | four step-down transformers T1–T4 at one screen size, 0.7 s each; 降压 / STEP DOWN stays in the same place | matched cuts | |+| 8 | 32.4–34.6 | …最终送进你家墙上的插座里。 | the block flashes by; the socket wall (switch, two sockets, L/N/PE wiring); plunge into the live hole | pan, hold, plunge | |+| 9 | 34.6–42.1 | 而当你插上手机充电器时… | out of the charger's pin: the whole charger (plug, fuse, bridge, capacitor, transformer, USB-C), 充电器 / CHARGER; push in to the bridge: 整流桥, 交流 → 直流 | reverse out, hold, push | |+| 10 | 42.1–52.9 | 说出来你可能不信… / 只不过… | detail callout: Butuo's bridge beside DB1 at the same size; 换流站; "=" and 同一个电路原理 at 47.6; 功率差 4 亿倍 at 49.4 | locked | verdict held 5.4 s before "=" |+| 11 | 52.9–54.5 | 你手机里的每一格电… | one pull-out from the charger to the whole board, the main line glowing | log zoom | |+| 12 | 54.5–60 | — | the whole board on a desk, noon window light; title block: 七毫秒 / SEVEN MILLISECONDS, LemoLab × Claude Opus 5.5 | slow push, 2° turn | end card |++## Voice-over++Chinese voice, edge-tts `zh-CN-XiaoxiaoNeural` at +20% (`demo/voice/lines.json`); each line starts at the time below, and its subtitle (Chinese over English) comes and goes with it. The English version (`sh demo/build.sh en`) speaks the English subtitle lines with `en-US-AvaNeural` at +10% (a few lines faster, up to +25%), starting at the same moments (`demo/voice_en/lines.json`; where a spoken line is shorter than its subtitle, the `say` field holds what is spoken).++| # | Start | Chinese | English |+|---|---|---|---|+| 1 | 0.40 s | 四川深山里发出来的电,仅仅七毫秒后,就到了两千公里外的江苏。 | Power made deep in the mountains of Sichuan reaches Jiangsu, 2,000 km away, in just 7 milliseconds. |+| 2 | 5.58 s | 平时我们家里用的电,电流是来回摆动着走的,叫做交流电。 | The electricity in our homes swings back and forth as it flows. It's called alternating current, AC. |+| 3 | 10.22 s | 如果直接送去太远的地方,在路上就会白白损耗掉很多。 | Sent that far as it is, a lot of it would simply be lost on the way. |+| 4 | 14.55 s | 所以,电得先进一趟换流站,变成只朝一个方向跑的直流电。 | So first it goes through a converter station and becomes direct current, DC, flowing one way only. |+| 5 | 19.24 s | 然后再顺着这根两千多公里长的电线,一路狂奔到江苏。 | Then it races along this line, more than 2,000 km long, all the way to Jiangsu. |+| 6 | 23.53 s | 全程只要七毫秒,连眨一下眼睛的时间都不到。 | The whole trip takes 7 milliseconds, less than the blink of an eye. |+| 7 | 27.15 s | 到了终点站,它会被重新变回交流电,再把电压一级一级降下来,最终送进你家墙上的插座里。 | At the end it's turned back into AC, stepped down level by level, and sent to the socket in your wall. |+| 8 | 34.20 s | 而当你插上手机充电器时,充电头里其实也藏着一个叫整流桥的小零件,正在把交流电重新变回直流电。 | Plug in your phone charger, and inside it a tiny part called a bridge rectifier turns the AC back into DC. |+| 9 | 42.24 s | 说出来你可能不信,它和换流站里那个几层楼高的大家伙,用的是同一个电路原理。 | Believe it or not, it works on the same circuit principle as the giant, storeys tall, in the converter station. |+| 10 | 48.39 s | 只不过,换流站那边的功率,是这个小充电头的整整四亿倍。 | Only the station's power is a full 400 million times that of this little charger. |+| 11 | 53.05 s | 你手机里的每一格电,都是跨越千山万水,这么跑过来的。 | Every bar of charge on your phone came this far, across mountains and rivers. |++## Score structure++Voice first: the bed (music and room tone) is ducked 9.5 dB under each line and sits about 17 dB under the voice; effects drop 7 dB. 100 BPM, G (the mains hum on G1). AC is a gated tone (slowed to 1.1 Hz while the voice explains it, dying away over the loss board); at Butuo (16.3) the gate smooths into a steady tone, the kick, ticks and bass enter, an arpeggio climbs through the ride with a glockenspiel at each 500 km pad; impact at 23.0, a bell for 7 ms, AC again at 27.4, four relays one step lower each, cicadas and an air-conditioner drone at the socket, suction and a pop through the hole; in the charger a faint whine, a high gated tone that smooths at the bridge (39.4); in the verdict a low tone (the station) under the high one, a clean G major chord on "=". Pull-out whoosh and pad, the last hit at 54.8, the hum to the end. −16.0 LUFS integrated, −4.5 dBTP.++## Palette & props++Mask greens #05190F / #1C6A44 / #4AA977, gold #D9B25B, bare-copper dam bar #C9784A, silk #F2EEE1, current amber (255,190,84), water silver (170,214,226). Props: the dam with 16 penstocks and generators (a step-up coil on every lead), connector J2; the bridge footprint (a diamond package with four diode symbols and a pad at each vertex: AC in at the left, return via at the right, + top, − bottom), converter transformers, AC filter banks, smoothing reactors, valve-hall courtyards; the corridor geography (octilinear Yangtze with five tributaries, four lakes, the east coast, real cities as test points, three more unlit ±800 kV lines); the loss board (one long bus, a ruler, test points); a city module (streets as channels, buildings as pad grids); a street module (a block of 18 floors as a lit pad array, pole transformer, a socket wall with a switch and a second socket, L/N/PE wiring, a sun and a clock at noon); the charger (plug blades, L/N pads, F1, RV1, CX1, DB1, C1, T1 over an isolation slot, CY1, U1, U2, C2, USB-C).++## End card++The board's own title block, top right of the corridor board, plotted at 54.8: 七毫秒 (≈ 75 px) / SEVEN MILLISECONDS; at 56.0 the row LemoLab × Claude Opus 5.5 (≈ 25 px caps); REV A / SHEET 1 OF 1 in its corner. No voice after 57.0; held to 60.0 under the window light. The "LemoLab × Claude Opus 5.5" sign-off belongs to this library's demo only; a user's film carries no LemoLab credit and no copy of this card.++## Build notes++- One command: `sh styles/circuit-board/demo/build.sh` (Chinese voice → `circuit-board.mp4`) or `sh styles/circuit-board/demo/build.sh en` (English voice → `circuit-board-en.mp4`). It cuts the subtitle font, voices and checks every line, exports the events, scores and mixes, renders, masters, writes `circuit-board.srt`, runs the reading-time check and renders the poster and gallery still without the subtitle bar.+- Files in `demo/`: `index.html`; `src/main.js` (timeline: cameras, scenes, subtitles, sound events), `src/world.js` (corridor board, 1 unit ≈ 1 km), `src/city.js` (10 m), `src/house.js` (10 cm), `src/charger.js` (mm), `src/loss.js` (the loss board), `src/levels.js` (nesting), `src/render.js`, `src/post.js`, `src/parts.js`, `src/geo.js`, `src/font.js`, `src/hanzi.js`, `src/palette.js`; `voice/` and `voice_en/` (`lines.json`, `dur.json`), `data/subs_en.json` (English subtitles); `audio.py` → `mix.wav` / `mix_en.wav`; `tools/subset.py` (subtitle font), `tools/srt.py` (subtitles file), `tools/sheet.sh` (0.5 s contact sheet into `out/`).+- Reading time: `window.TEXTS(t)` reports every word printed on the boards and `readcheck.mjs` passes on all of them. The subtitle bar follows the voice (about 5.6 characters a second), so it is reported only with `--q subs=1`. `?nosub=1` renders without subtitles.+- The page always draws at 1920×1080 and is scaled by CSS, so stills at other sizes keep the framing. 1080p frames take 30–75 ms, about 180–270 ms in the pull-out (several nested boards plus motion-blur sub-frames).+- Demo-specific pitfalls: the sending station is reported both as 布拖换流站 and 白鹤滩换流站 (the voice and screen only say 换流站); the dam complex is drawn about 50× its map scale, so the river's first reach is schematic; the AC bus and the DC pair cross the river (a trace may cross a bare channel); the four step-down cuts use one on-screen symbol size (300 px), so each transformer's world size follows from its cut's zoom, and the 降压 label sits at the same screen place in all four so it reads as one; keep picture text above the subtitle band.diff --git a/styles/circuit-board/STYLE.md b/styles/circuit-board/STYLE.mdnew file mode 100644index 0000000..d9efcd3--- /dev/null+++ b/styles/circuit-board/STYLE.md@@ -0,0 +1,121 @@+# Circuit Board — Style Prompt++> The subject is drawn as a printed circuit board seen from straight above: the world is copper under green solder mask, routes are traces, places are pads, words are white silkscreen, and what flows (power, water, signals, goods) is light running along the copper. The camera rides that light and jumps between the scale of a map and the scale of a single component.+> References (grammar only): real PCB design files and assembly drawings (layers, clearances, designators, detail callouts); macro photography of boards (shallow depth of field, gold sheen, soft key light); schematic and single-line diagrams (one symbol stands for one function). Draw your own boards: never copy a real board layout, a logo or a part marking.++## 1. Essence, and what it is not++- A top-down board in every frame: copper pour with clearances cut around everything, traces with 0/45/90° runs and mitred corners, gold pads and vias, white monoline silkscreen. Nothing is drawn in perspective.+- Information moves as light on copper. The way the light moves *is* the explanation: a pulse, a stream, a rocking dash, a pad that flashes.+- Two scales on one board: whole regions (a map, a supply chain, a city) are drawn in the same language as single components, and the camera passes between them without changing medium.+- Only real things are drawn. Every trace, pad and label stands for something in the subject; empty copper is filled with what boards really have (stitching vias, via fences, solder-mask mottling), never with decorative routing.+- Not the library's Engineering Briefing Board (a whiteboard on which real photos are pinned and written over in marker): here there are no photos and no handwriting; the subject itself becomes copper, pads and silkscreen, and information travels as light along the traces. Not a blueprint (no white-on-blue linework, no paper), not a sci-fi HUD (no glass, no floating panels, no glowing UI chrome), not a 3D circuit "city" (no buildings rising, no perspective).++## 2. Materials & rendering++Layers bottom-up, all in board space under one world → screen camera:+1. **Laminate (FR-4):** dark green, a glass-weave basket texture in two crossfaded octaves so its on-screen size stays bounded at every zoom. Bottom-layer copper may show through faintly.+2. **Copper pour:** fills the board; everything is a **clearance** punched out of it (channels, lakes, sea, keep-outs around parts and traces). Rendered twice: a lighter rim pass with the plain clearance, then the fill pass with the clearance grown by ~1.6 px, so every copper edge gets a bevelled rim. A soft mottling texture sits only on the pour (solder mask is never perfectly flat).+3. **Traces:** rim colour stroke + narrower fill stroke, round caps; a channel of bare laminate runs on both sides (the clearance). Parallel traces keep the pour out of the gap between them when they are a pair.+4. **Exposed metal:** ENIG-gold pads (rect, round, square pin-1) with a sheen band on the top third and a dark drill hole; vias are gold rings with dark bores; bare copper (salmon with a vertical gradient and brushed streaks) only for one heavy, special part. Fiducials and mounting holes at board corners.+5. **Silkscreen:** off-white monoline strokes with a pinhole texture punched out, slightly blurred (0.35 px). Outlines, designators, polarity marks, component symbols, labels.+6. **Light:** an additive layer (glow) with two blurs (≈24 px and ≈5 px) under a sharp copy. Current, water, lit pads all live here.+7. **Screen space (once per frame):** a soft warm key light drifting from the upper left, shallow depth of field (a blurred copy faded in at the top and bottom bands, stronger in macro shots, weak or off where text must be read), out-of-focus motes of light drifting with parallax in front of the board, a vignette, film grain at mux. A window's light (a soft parallelogram with a mullion shadow) may fall on the board when the whole board is on a desk.+Level of detail: textures crossfade between octaves; small features (vias, designators, rims) fade out before they go sub-pixel, so zooms never shimmer. Nested boards (a module inside a board) are separate boards composited into their footprint, so a continuous zoom can cross six or more orders of magnitude without precision loss.++## 3. Colour logic++- Ground: green solder mask in three values (dark laminate, mid pour, light rim/trace). The film is green; never recolour the mask per scene.+- Metal: gold for pads and vias, one bare-copper accent at most.+- Ink: one off-white for all silkscreen.+- Light carries meaning and is the only saturated colour: **amber** for energy/current (with a near-white core), **silver-cyan** for a second kind of flow (water, data, goods) when the story has two. A third flow gets a third light colour only if it must be told apart; red is reserved for a fault and appears at most once.+- Dark (bare laminate, sea, holes) for what is absent.+Example: laminate #05190F, pour #1C6A44, rim #4AA977, gold #D9B25B, silk #F2EEE1, current (255,190,84), water (170,214,226).++## 4. Type & subtitles++- All type is silkscreen in one **monoline stroke font routed like traces** (0/45/90° strokes, chamfered corners, round caps), drawn in code. Chinese uses the same rules: every hanzi hand-routed on a 0/45/90° grid with the same stroke width as the Latin line beside it. Use simplified characters only and proof every glyph at large size before use.+- Text is world-anchored and **plotted stroke by stroke**; it stays on the board and is still there when the camera pulls back.+- Roles: labels (a Chinese line above a smaller English line, same stroke width), board-native text in one language (designators, voltages, timestamps, km, values), micro texture (pinyin tags, notes, REV/sheet lines) which may fade below reading size.+- Reading: a label must be fully in frame and stay there for its reading time (≥ 1.5 s + characters at 4.5/s CJK, 15/s Latin). Never let text sit in the depth-of-field bands; never cut text at the frame edge in a held shot. Title caps ≥ 60 px at 1080p.+- With a voice, every line gets a subtitle in the bottom safe area: a dark translucent plate, Chinese over English (an open-licence sans, e.g. Noto Sans SC, subset to the characters used; never a system font), 34 px / 24 px at 1080p. The board then prints only the voice's key words and numbers, never whole sentences. Keep picture text above the subtitle band.++## 5. Motion quality++- 30 fps, everything on ones. `render(t)` depends on t only; motion blur from measured screen motion (180° shutter, sub-frames from 1 to ~20), never across a cut.+- Kinds of current, told apart only by how the light moves:+ - **AC / alternating:** short dashes rocking back and forth along the trace (a slowed mains frequency) over a faint energised line.+ - **DC / one-way:** a continuous lit stream behind a travelling head, with slow streaks inside and an afterglow that dims slowly behind the head.+ - **Step-down:** the trace gets thinner and the dashes smaller.+ - **Water / second flow:** several parallel streamlines of moving dashes at different speeds, faster in the middle, with short glints.+- Pads flash on arrival (a quick bright bloom, then a steady glow). Components "conduct": the symbol's internal edges glow while current passes.+- Silkscreen appears only by plotting; copper and pads never pop in. What never moves: the board itself (only the camera moves).++## 6. Camera grammar++Straight-down camera always (rotation about the view axis allowed, small). Moves:++| Move | What it expresses | Can serve |+|---|---|---|+| Ride the pulse (camera locked to a moving head, head on a third) | following one thing through a system | a delivery route; a signal path; a single order through a process |+| Rise while following (zoom out during the ride until both ends are in frame) | the whole length becomes visible | a distance; a supply chain end to end; a timeline |+| Crash zoom onto a pad | arrival, impact | a deadline met; a package delivered; a test result |+| Locked macro hold | reading, comparing, verdict | two numbers side by side; a spec; a rule |+| Whip along a trace | jump to the next station | the next stage; skipping ahead |+| Matched cut on a centred symbol (same symbol, same screen size, the world around it changes scale) | the same step repeated at every level | step-downs; repeated approvals; hand-offs |+| Plunge through a hole / via, reverse out of another hole | entering a smaller world | into a device; into a building; into a file |+| Continuous pull-out across nested boards | everything was one board | the big picture after the detail; the system behind one object |++Framing rules: the lit subject sits on a third or dead centre for symbols; at least two layers of detail around it (background copper/vias/routes, foreground motes or depth-of-field blur); the board edge appears only when the whole board is the subject. Transitions: motion-into-motion and matched cuts; no fades, no wipes, no page turns.++## 7. Sound palette++All synthesised: sine/saw tones, pulse waves, FM bells and glockenspiel, relay clicks (two-click transients), soft kicks and 16th ticks, filtered noise. Tune the drone to the mains hum (50 Hz ≈ G1; 60 Hz ≈ B♭1) so the hum belongs to the key. Rule the ear can follow: an **amplitude-gated tremolo tone = alternating**, a **steady tone = direct**; a component that converts one into the other is heard as the tremolo smoothing into the long tone. Arrivals are relay clicks or a filtered noise burst; a step-down is a relay one step lower each time; plotting silkscreen is a faint scratch of grains. Outside sounds (water, cicadas, traffic) only behind a low-pass, as if heard through a wall. Silence: drop the rhythm before a verdict, keep only long tones. With a voice, the voice leads: duck the bed so it sits 15–18 dB under the speech, effects a few dB. Mix around −16 LUFS before mastering, true peak under −3 dBTP, lean low end (high-pass ≈ 55 Hz).++### Voice-over and subtitles++When the film explains something, a voice tells it and the board shows it at the same moment: each spoken line has one picture action (a pad lights, a stream changes shape, a tag prints). Every line gets a subtitle in the bottom safe area, a Chinese line over an English line on a dark translucent plate, appearing and leaving with the voice; the board itself prints only the key words and numbers the voice says (a name, a value, a verdict), never whole sentences. Keep the voice on top: the bed sits 15–18 dB under it and rises in the gaps. Pick one calm, clear voice for the whole film; numbers and units are spoken in full.++## 8. Native moves++- **Flow becomes current.** A second flow (silver) enters a row of pads; each pad lights on a beat and amber leaves on its other side. *Fits content like:* raw material entering a factory and leaving as product; requests hitting servers and leaving as responses; donations becoming grants.+- **Pulse-path explainer.** Every stage of a process is a component on one trace; the way the light changes (rocking, streaming, thinning) tells what each stage does. *Fits content like:* a payment's clearing path; a parcel's sorting hubs; a message across a network.+- **The map is a board.** Geography re-routed octilinear as copper and channels; rivers, lakes and coasts are clearances with via fences; cities are test points; corridors are buses of parallel traces. *Fits content like:* a pipeline across countries; a migration route; the cables under an ocean.+- **Detail callout.** An assembly-drawing circle that shows another place of the same board (or another board) at a chosen scale next to the thing it is compared with. *Fits content like:* the same mechanism at two sizes; a lab prototype beside the plant; yesterday's version beside today's.+- **Nested boards.** A module footprint on a board is a complete board of its own; plunge into it, or pull out through every level in one move. *Fits content like:* a country → city → building → device; an organisation → team → person; a chip → core → transistor.+- **Matched step-down.** The same symbol held centred while the board around it changes scale on each cut. *Fits content like:* voltage levels; approval tiers; zoom levels of a map.+- **Timestamp tags.** Silk frames printing times at two stations, the second tag repeating the first digit-for-digit above its own. *Fits content like:* latency; a race between two routes; before and after.++## 9. Pitfalls of the medium++- **Flat pour.** A board that is all mid-green reads as an empty slide. Fill with real board texture: stitching vias that stay visible at map scale, fences along every clearance, mottling, micro silk, other unlit routes that exist in the subject.+- **Decorative routing.** Traces that mean nothing make viewers ask what they are. Draw only real routes; texture comes from vias and mask, not invented traces.+- **Lines crossing on one layer.** Two traces can't cross on the same copper: use a via to the bottom layer, or route around. A trace may cross a bare channel (a river, a street).+- **Overexposed light.** Wide traces with additive bloom turn into white bars. Cap glow widths and flash radii in pixels, keep the amber body and a thin core.+- **Text in the blur or under the frame edge.** Depth of field and the vignette eat the top and bottom bands: keep labels out of them, or turn the blur down in reading shots.+- **Too-fast holes.** A plunge into a hole under 0.6 s reads only as "darkness". Hold on the hole first, then plunge; come out of another hole the opposite way.+- **Precision.** Zooming a single coordinate system over many orders of magnitude breaks the canvas transform. Nest boards (each with moderate units) and convert cameras between levels in double precision.+- **Hanzi in a stroke font.** Automatic skeletons of fonts lose dots and strokes; route each character by hand and proof traditional/simplified forms (鹤 not 鶴, 换 not 換).++## 10. Engine++All in `demo/src/`:++- `render.js` — `Board`: draws one board (a world module) for a camera `{x,y,z,r}`: laminate, copper (two-pass rim), traces, pads, vias, silk, glow (`acDashes`, `dcStream`, `flow`, `penFlow`, flashes), `texts()` for reading checks.+- `levels.js` — nested boards: `makeLevels`, `toChild`/`toParent`, `baseOf`, `drawLevel` (composites each visible child board into its footprint).+- `font.js` + `hanzi.js` — the routed monoline font; `drawText(ctx, str, x, y, cap, {sw, progress})` plots by stroke length.+- `parts.js` — footprints: `bridge` (diamond rectifier), `xformer`, `reactor`, `capBank`, `chip`, `ecap`, `xfmr`, `ground`, `tag`.+- `geo.js` — `octi` (0/45/90° routing through waypoints), `offset` (parallel lanes), `measure/at/sub`.+- `post.js` — key light, depth of field, motes, window light, vignette.+- Minimal new use: a world module exporting `BOARD`, `TRACES`, `PADS`, `SILK`, `LABELS` (e.g. three warehouses as pads joined by a bus, one `xformer` as a sorting hub) and a scene with one `dcStream` is a complete film board.++## 11. Variation space++The agent decides the structure, the stations, the scales visited, the camera path, the pacing and which flows get which light. Range, far from the demo:+- Structures: a single packet's round trip and the time it took; three routes raced side by side on parallel buses; one board revealed component by component like an exploded view, ending on the whole.+- Openings: a via drilled through in macro, light rising out of it; a whole board on a desk, the camera diving to one pad; a single silk label plotting itself in the dark, then the copper lighting under it.+- Endings: the last pad lights and the board's power LED stays on; a pull-out to many identical boards in a rack; the title block of the board printing the answer.++---++How our demo was made (story, shots, score, end card, build): [DEMO.md](DEMO.md). Read it after your treatment exists.diff --git a/styles/circuit-board/circuit-board.srt b/styles/circuit-board/circuit-board.srtnew file mode 100644index 0000000..a6dfcff--- /dev/null+++ b/styles/circuit-board/circuit-board.srt@@ -0,0 +1,54 @@+1+00:00:00,350 --> 00:00:05,401+四川深山里发出来的电,仅仅七毫秒后,就到了两千公里外的江苏。+Power made deep in the mountains of Sichuan reaches Jiangsu, 2,000 km away, in just 7 milliseconds.++2+00:00:05,530 --> 00:00:10,042+平时我们家里用的电,电流是来回摆动着走的,叫做交流电。+The electricity in our homes swings back and forth as it flows. It's called alternating current, AC.++3+00:00:10,170 --> 00:00:14,368+如果直接送去太远的地方,在路上就会白白损耗掉很多。+Sent that far as it is, a lot of it would simply be lost on the way.++4+00:00:14,500 --> 00:00:19,061+所以,电得先进一趟换流站,变成只朝一个方向跑的直流电。+So first it goes through a converter station and becomes direct current, DC, flowing one way only.++5+00:00:19,190 --> 00:00:23,347+然后再顺着这根两千多公里长的电线,一路狂奔到江苏。+Then it races along this line, more than 2,000 km long, all the way to Jiangsu.++6+00:00:23,480 --> 00:00:26,967+全程只要七毫秒,连眨一下眼睛的时间都不到。+The whole trip takes 7 milliseconds, less than the blink of an eye.++7+00:00:27,100 --> 00:00:34,023+到了终点站,它会被重新变回交流电,再把电压一级一级降下来,最终送进你家墙上的插座里。+At the end it's turned back into AC, stepped down level by level, and sent to the socket in your wall.++8+00:00:34,150 --> 00:00:42,063+而当你插上手机充电器时,充电头里其实也藏着一个叫整流桥的小零件,正在把交流电重新变回直流电。+Plug in your phone charger, and inside it a tiny part called a bridge rectifier turns the AC back into DC.++9+00:00:42,190 --> 00:00:48,207+说出来你可能不信,它和换流站里那个几层楼高的大家伙,用的是同一个电路原理。+Believe it or not, it works on the same circuit principle as the giant, storeys tall, in the converter station.++10+00:00:48,340 --> 00:00:52,872+只不过,换流站那边的功率,是这个小充电头的整整四亿倍。+Only the station's power is a full 400 million times that of this little charger.++11+00:00:53,000 --> 00:00:57,127+你手机里的每一格电,都是跨越千山万水,这么跑过来的。+Every bar of charge on your phone came this far, across mountains and rivers.diff --git a/styles/circuit-board/demo/CREDITS b/styles/circuit-board/demo/CREDITSnew file mode 100644index 0000000..48a5ffa--- /dev/null+++ b/styles/circuit-board/demo/CREDITS@@ -0,0 +1,29 @@+Seven Milliseconds (七毫秒) — Circuit Board (Lemo-Opuscar) · LemoLab × Claude Opus 5.5++No company, brand or logo appears. Converter stations and the hydropower station are named by place only. The boards,+their layout, the charger and every mark are our own drawing in code. Real facts and their sources: FACTS.md.++IMAGES, FOOTAGE, MODELS+- None. Every board (corridor, city, street, charger, loss board) is drawn in code (src/). No photographs, no scans,+ no map dataset (rivers, lakes, coast and city positions are hand-routed from approximate public coordinates),+ no AI-generated images, no 3D models.++LETTERING+- "Routed", the single-line silkscreen font (src/font.js, Latin; src/hanzi.js, the 48 hanzi the boards print, hand-routed+ on a 0/45/90-degree grid): original drawings for this film, not traced from any font.++FONTS (SIL Open Font License 1.1; not in git, build.sh downloads the source from github.com/google/fonts)+- Noto Sans SC (variable, NotoSansSC[wght].ttf) — Google / Adobe, instanced at weight 500 and subset by tools/subset.py to+ the characters of the subtitles (fonts/NotoSansSC-Medium-sub.ttf). Licence: fonts/OFL-NotoSansSC.txt++VOICE+- Microsoft edge-tts (online service): zh-CN-XiaoxiaoNeural (Chinese, +20%), en-US-AvaNeural (English version),+ generated by the library's core/tts/tts_zh.py and checked with core/tts/asr_check.py.++MUSIC & SOUND+- Original score and sound design written for this film in audio.py: synthesis in numpy (tones, gates, bells,+ glockenspiel, kick, ticks, bass, arpeggio, pads, relays, water, cicadas, hum) through the library's core/audio/sfx.py.+ No samples.++CODE+- Easing helpers from the library's core/lib.js.diff --git a/styles/circuit-board/demo/FACTS.md b/styles/circuit-board/demo/FACTS.mdnew file mode 100644index 0000000..c94aead--- /dev/null+++ b/styles/circuit-board/demo/FACTS.md@@ -0,0 +1,43 @@+# Facts on screen and in the voice++Every number or name the film prints or says, where it comes from and the source's own words; what could not be sourced says how it was worked out. The voice text is `voice/lines.json` (Chinese) and `data/subs_en.json` (English, also spoken in the English version).++## Sources++- [S1] Baihetan Dam, Wikipedia — https://en.wikipedia.org/wiki/Baihetan_Dam — "equipped with 16 hydro-generating units each having a capacity of 1 gigawatt"; "All hydro-generating units of the Baihetan hydropower station became fully operational on 20 December 2022."+- [S2] The Paper (澎湃新闻) — https://www.thepaper.cn/newsDetail_forward_21364518 — "其中,左岸、右岸各建设8台百万千瓦级机组,分别送电江苏、浙江。"+- [S3] IT之家, Baihetan–Jiangsu line in service — https://www.ithome.com/0/627/417.htm — "白鹤滩-江苏工程起于四川省凉山州布拖县,止于江苏省苏州常熟市,途经四川、重庆、湖北、安徽、江苏 5 省(直辖市),线路全长 2080 公里,新建白鹤滩、虞城 2 座换流站。" "工程额定电压 ±800 千伏、额定输送容量 800 万千瓦……2022 年 7 月竣工投产。"+- [S4] China News Service (中国新闻网), 2022-06-20 — https://www.chinanews.com.cn/gn/2022/06-20/9783791.shtml — "以白江线为例,起于四川凉山布拖换流站,止于江苏常熟虞城换流站。" On UHV transmission: "输电距离远、输送容量大、运行损耗低……特高压让“电从远方来”成为现实".+- [S5] Structural study of ±800 kV valve halls (steel-framed buildings housing the converter valves) — https://aminer.org/pub/53e9a42bb7602d9702d47000/structure-form-selection-of-the-valve-hall-and-control-building-of-kv+- [S6] GB/T 156, 标准电压 (Chinese national standard voltages): household supply 220 V, 50 Hz.++## On screen++| Printed | Claim | Source / how |+|---|---|---|+| 白鹤滩 / BAIHETAN (small, texture), 16 generator pads G1–G16 | Baihetan has 16 units of 1 GW | [S1] |+| G1–G8 run to the Jiangsu line; G9–G16 leave through connector J2 | eight units on each bank; one bank sends to Jiangsu, the other to Zhejiang | [S2]. The picture never prints 左岸/右岸 |+| 换流站 / CONVERTER STATION (both ends) | converter stations at Butuo and at Yucheng, Changshu | [S3], [S4]. The sending station is also reported as 白鹤滩换流站; it stands in Butuo county, and the film names neither |+| 四川 / SICHUAN, 江苏 / JIANGSU, 2,080 公里 / 2,080 km | the line runs 2,080 km from Sichuan to Jiangsu | [S3] |+| 7 毫秒 / 7 ms | worked out: 2,080 km ÷ 299,792 km/s ≈ 6.94 ms. On an overhead line the wave travels a little slower than light in vacuum, so the voice says "only" and the figure is rounded to 7. What crosses in 7 ms is the electromagnetic signal, not the electrons, which drift far more slowly | arithmetic |+| test pads every 500 km (small "500 km" texture) | placed at 500/2080, 1000/2080, 1500/2080 of the drawn route's length; the route itself is schematic | arithmetic |+| 220 V ~ 50 Hz (small, on the socket) | household supply in mainland China | [S6] |+| 充电器 / CHARGER, USB-C · 20 W (small) | a fictional 20 W phone charger; its layout is invented. The chain plug → fuse → bridge rectifier → bulk capacitor → flyback transformer → output is the common one for small chargers | — |+| 整流桥 / BRIDGE RECTIFIER, 交流 → 直流 / AC → DC, 同一个电路原理 / THE SAME CIRCUIT | both ends are drawn with the bridge-rectifier symbol meaning "AC becomes DC" (the inverter is its mirror). Simplification: a real ±800 kV converter uses 12-pulse thyristor valve groups, not four diodes; the principle (bridge rectification) is the same | stated as a principle |+| 功率差 4 亿倍 / 400 MILLION × THE POWER | 8,000 MW (the line's rated capacity) ÷ 20 W (the film's charger) = 4 × 10⁸ | [S3] + arithmetic |++Drawn but not labelled (texture, not claims): the Yangtze with the Jinsha, Jialing, Wu, Han, Xiang and Gan rivers; Dongting, Poyang, Chaohu and Taihu lakes; the east coast; real cities as round test points with pinyin tags; three more ±800 kV lines of the west-to-east corridor (to Suzhou, Shanghai and Jinhua), never lit. All routes are schematic (octilinear), not survey-accurate. No provincial or national borders are drawn; the board shows only the Yangtze corridor.++## In the voice++| Line | Claim | Source / how |+|---|---|---|+| 四川深山里发出来的电 | the Jiangsu line starts at Butuo, Liangshan, Sichuan, fed by Baihetan in the mountains on the Sichuan–Yunnan border | [S3], [S4] |+| 仅仅七毫秒 / 全程只要七毫秒 | ≈ 6.9 ms | arithmetic (above) |+| 两千公里外 / 两千多公里长 | 2,080 km | [S3] |+| 如果直接送去太远的地方,在路上就会白白损耗掉很多 | long distance is why UHV DC is used, and low running loss is one of its stated advantages; the voice says it without a figure | [S4] |+| 电得先进一趟换流站,变成只朝一个方向跑的直流电 / 到了终点站,它会被重新变回交流电 | converter stations at both ends | [S3] |+| 再把电压一级一级降下来,最终送进你家墙上的插座里 | stepped down through the grid to 220 V at the socket | [S6]; the steps are not numbered |+| 换流站里那个几层楼高的大家伙 | a spoken description, not a measured figure: the converter valves hang in a valve hall, a steel-framed building [S5] tens of metres tall; no official height for this station was found, so no number is said or printed | colloquial |+| 用的是同一个电路原理 | both rectify with a bridge (simplification above) | — |+| 是这个小充电头的整整四亿倍 | 8,000 MW ÷ 20 W = 4 × 10⁸ | [S3] + arithmetic |diff --git a/styles/circuit-board/demo/audio.py b/styles/circuit-board/demo/audio.pynew file mode 100644index 0000000..e883949--- /dev/null+++ b/styles/circuit-board/demo/audio.py@@ -0,0 +1,200 @@+"""Seven Milliseconds — score, sound design and mix, all synthesised (no samples, no piano, no strings).+Run from the library root: .venv/bin/python styles/circuit-board/demo/audio.py [en]+(with `en`: the same score and effects under the English voice from voice_en/, written to mix_en.wav)+Reads events.json (node core/render/events.mjs <film>). Writes mix.wav (48 kHz stereo, exactly the film's length).++Key G, 100 BPM, tuned to the mains: the 50 Hz hum sits on G1 (49 Hz).+The rule the ear follows: AC = a gated tremolo tone, DC = one steady long tone. The water turns into the hum,+the hum is chopped (AC), the bridge smooths it (DC); the same happens again, two octaves up, inside the charger.+"""+import json, os, sys, subprocess+import numpy as np+import soundfile as sf+from scipy.signal import sawtooth++HERE = os.path.dirname(os.path.abspath(__file__))+LIB = os.path.abspath(os.path.join(HERE, '../../..'))+sys.path.insert(0, os.path.join(LIB, 'core/audio'))+import sfx # noqa: E402+from sfx import SR, t_, bp, lp, hp, noise, add # noqa: E402++LANG = sys.argv[1] if len(sys.argv) > 1 else 'zh'+VODIR, OUTNAME = ('voice_en', 'mix_en.wav') if LANG == 'en' else ('voice', 'mix.wav')+EV = json.load(open(os.path.join(HERE, 'events.json')))+EV = EV['ev'] if isinstance(EV, dict) else EV+DUR = 60.0; N = int(DUR * SR)+BEAT = 60 / 100; S16 = BEAT / 4+rng = np.random.default_rng(7)+def hz(m): return 440.0 * 2 ** ((m - 69) / 12)+def buf(): return np.zeros((N, 2), np.float32)+def ev(ty): return [e for e in EV if e['type'] == ty]+def fade(x, a=0.01, b=0.05):+ n = len(x); ia, ib = min(n, int(a * SR)), min(n, int(b * SR))+ if ia: x[:ia] *= np.linspace(0, 1, ia)+ if ib: x[-ib:] *= np.linspace(1, 0, ib)+ return x++# ---------------- voices ----------------+def tone(m, d, bright=0.3): # a soft synth tone: sine + a little saw, low-passed+ tt = t_(d); f = hz(m)+ return lp(np.sin(2 * np.pi * f * tt) * 0.8 + sawtooth(2 * np.pi * f * tt) * bright, min(9000, f * 6))+def gate(x, rate, depth=0.85, ph=0.0): # AC: amplitude gated at `rate` Hz+ tt = np.arange(len(x)) / SR; g = 0.5 + 0.5 * np.sign(np.sin(2 * np.pi * rate * tt + ph))+ from scipy.ndimage import uniform_filter1d+ g = uniform_filter1d(g, int(0.006 * SR)); return x * (1 - depth + depth * g)+def bell(m, d=1.6, ratio=3.5, idx=1.8):+ tt = t_(d); f = hz(m); I = idx * np.exp(-tt / 0.3)+ return np.sin(2 * np.pi * f * tt + I * np.sin(2 * np.pi * f * ratio * tt)) * np.exp(-tt / 0.6) * np.minimum(1, tt / 0.002)+def glock(m, d=1.2):+ tt = t_(d); f = hz(m); return (np.sin(2 * np.pi * f * tt) + 0.3 * np.sin(2 * np.pi * f * 2.76 * tt) * np.exp(-tt / 0.08)) * np.exp(-tt / 0.45) * np.minimum(1, tt / 0.001)+def relay(pitch=1.0):+ x = np.zeros(int(0.06 * SR)); c = sfx.click(1.3 * pitch, 1.0); x[:len(c)] += c[:len(x)]+ c2 = sfx.click(1.0 * pitch, 0.6); s = int(0.011 * SR); x[s:s + len(c2)] += c2[:len(x) - s]; return x+def kick():+ d = 0.4; tt = t_(d); f = 46 + 70 * np.exp(-tt / 0.03)+ return np.sin(2 * np.pi * np.cumsum(f) / SR) * np.exp(-tt / 0.17)+def tick(v=1.0):+ d = 0.03; tt = t_(d); return bp(noise(d), 5000, 11000) * np.exp(-tt / 0.0025) * v+def arp(m, d=0.14, cut=3000):+ tt = t_(d); f = hz(m); x = sawtooth(2 * np.pi * f * tt, 0.5) * np.minimum(1, tt / 0.003) * np.exp(-tt / 0.08)+ return lp(x, cut)+def pad(ms, d, att=1.2, rel=1.4, cut=1600):+ tt = t_(d); x = np.zeros_like(tt)+ for m in ms:+ for c in (-6, 0, 6): x += sawtooth(2 * np.pi * hz(m) * 2 ** (c / 1200) * tt + rng.random() * 6)+ e = np.minimum(1, tt / att) * np.minimum(1, np.maximum(0, d - tt) / rel)+ return lp(lp(x / (3 * len(ms)), cut), cut) * e+def hum(d, v=1.0):+ tt = t_(d); f = hz(31) # G1 ≈ 49 Hz: the mains, tuned to the key+ return (0.6 * np.sin(2 * np.pi * f * tt) + 0.5 * np.sin(4 * np.pi * f * tt) + 0.3 * np.sin(6 * np.pi * f * tt) + 0.15 * np.sin(8 * np.pi * f * tt)) * v+def sub_hit(d=1.4, f0=80, f1=34):+ tt = t_(d); f = f1 + (f0 - f1) * np.exp(-tt / 0.15); return np.sin(2 * np.pi * np.cumsum(f) / SR) * np.exp(-tt / 0.5) * np.minimum(1, tt / 0.003)++mus, fx, amb = buf(), buf(), buf()+T_IN, T_ARR, T_AC, T_DB, PULL0 = 16.3, 23.0, 27.4, 39.4, 52.9++# ---------------- 0–4.7: water, sixteen units, the water becomes the hum ----------------+d = 5.2; tt = t_(d)+roar = lp(noise(d), 900) * 0.7 + bp(noise(d), 900, 5000) * 0.3+cut_env = np.clip(1 - (tt - 4.2) / 0.9, 0, 1)+add(amb, fade(roar * np.minimum(1, tt / 0.02) * (0.65 + 0.35 * cut_env) * np.where(tt > 4.2, cut_env, 1)), 0.0, 0.10)+add(fx, hp(sub_hit(1.5, 70, 30), 40) + lp(noise(1.5), 300) * np.exp(-t_(1.5) / 0.2) * 0.6, 0.0, 0.3)+for e in ev('gen'):+ add(fx, relay(1.0 + 0.045 * e['i']), e['t'], 0.16, -0.5 if e['i'] % 2 else 0.5)+ add(mus, glock(67 + [0, 2, 4, 7, 9, 12, 14, 16][(e['i'] // 2) % 8]), e['t'], 0.025, 0.3 if e['i'] % 2 else -0.3)+add(amb, fade(hum(T_ARR - 4.2, 1.0) * np.minimum(1, t_(T_ARR - 4.2) / 0.8)), 4.2, 0.03)+# AC = a gated tone. Normal rate until 5.4, slow while the voice explains it (5.4–10.1), normal again+def ac_tone(t0, t1, m, rate, g, cut=None):+ d = t1 - t0; x = gate(tone(m, d, 0.25) + tone(m + 7, d, 0.15) * 0.6, rate, 0.8)+ if cut is not None: x = x * cut(t_(d))+ add(mus, fade(x, 0.05, 0.08), t0, g)+ac_tone(2.2, 5.4, 43, 100 / 60 * 4, 0.10)+ac_tone(5.4, 10.1, 43, 1.1, 0.10)+ac_tone(10.1, 14.4, 43, 100 / 60 * 4, 0.10, lambda tt: np.exp(-tt / 2.2)) # the loss: it dies away along the line+ac_tone(14.4, T_IN, 43, 100 / 60 * 4, 0.10)++# ---------------- Butuo: the tremolo smooths into one steady tone (DC); the groove starts ----------------+d = T_ARR + 0.1 - T_IN; x = (tone(43, d, 0.2) + tone(50, d, 0.1) * 0.5) * np.minimum(1, t_(d) / 0.04); add(mus, fade(x, 0.005, 0.05), T_IN, 0.09)+for e in ev('smooth'): add(fx, fade(bp(noise(0.25), 600, 6000) * np.exp(-t_(0.25) / 0.05)), e['t'], 0.08)+for i in range(int(T_IN / BEAT) + 1, int(T_ARR / BEAT)):+ tb = i * BEAT+ if 18.75 <= tb < 19.1: continue+ add(mus, hp(kick(), 48), tb, 0.12)+for i in range(int(T_IN / S16) + 1, int(T_ARR / S16)):+ add(mus, tick(1.0 if i % 4 == 0 else 0.5), i * S16, 0.035, 0.3 if i % 2 else -0.3)+BASS = [43, 43, 46, 41]+for i in range(int(T_IN / (BEAT / 2)) + 1, int(T_ARR / (BEAT / 2))):+ tb = i * BEAT / 2; m = BASS[int(tb // (4 * BEAT)) % 4] - 12+ d = 0.26; x = lp(sawtooth(2 * np.pi * hz(m) * t_(d), 0.4), 700) * np.minimum(1, t_(d) / 0.004) * np.exp(-t_(d) / 0.16)+ add(mus, x, tb, 0.09)+for e in ev('whip'): add(fx, sfx.whoosh(0.5), e['t'] - 0.05, 0.22); add(fx, hp(sub_hit(0.8, 60, 36), 40) * 0.6, e['t'] + 0.3, 0.14)+CH = {43: [55, 59, 62, 67, 71], 46: [58, 62, 65, 70, 74], 41: [53, 57, 60, 65, 69]}+for i in range(int((T_ARR - 19.1) / S16)):+ tb = 19.1 + i * S16; r = BASS[int(tb // (4 * BEAT)) % 4]; ch = CH.get(r, CH[43])+ p = (tb - 19.1) / (T_ARR - 19.1); m = ch[i % 5] + (12 if p > 0.5 and i % 10 >= 5 else 0)+ add(mus, arp(m, 0.14, 900 + 4500 * p), tb, 0.045 + 0.03 * p, ((i % 5) - 2) * 0.22)+for k, e in enumerate(ev('km')): add(mus, glock(79 + [0, 4, 7][k], 1.4), e['t'], 0.08, [-0.4, 0, 0.4][k])+add(mus, pad([55, 62, 67, 71], 3.0, 1.2, 0.4, 1800), 20.0, 0.10)++# ---------------- Yucheng: impact, the 7 ms bell, AC again ----------------+for e in ev('impact'):+ t0 = e['t']; add(fx, hp(sub_hit(1.8, 90, 32), 40), t0, 0.3); add(fx, hp(noise(0.3), 2000) * np.exp(-t_(0.3) / 0.03), t0, 0.12)+ add(mus, pad([43, 50, 55, 62], 1.6, 0.02, 0.6, 1400), t0, 0.12)+for e in ev('bell'): add(mus, bell(e['n'], 2.2), e['t'], 0.07, 0.25)+d = T_AC - T_ARR; x = tone(43, d, 0.2) * np.minimum(1, t_(d) / 0.05); add(mus, fade(x, 0.01, 0.05), T_ARR, 0.07)+ac_tone(T_AC, 32.4, 43, 100 / 60 * 4, 0.09)+for e in ev('chop'): add(fx, fade(bp(noise(0.2), 500, 4000) * np.exp(-t_(0.2) / 0.04)), e['t'], 0.07)+for e in ev('step'):+ i = e['i']; add(fx, relay(1.1 - 0.17 * i), e['t'], 0.32); add(fx, hp(sub_hit(0.5, 70 - 8 * i, 40 - 4 * i), 40), e['t'], 0.1)++# ---------------- the street: cicadas behind glass, an AC unit; into the hole ----------------+d = 34.1 - 32.4; tt = t_(d)+cic = bp(noise(d), 4200, 7200) * (0.55 + 0.45 * (0.5 + 0.5 * np.sign(np.sin(2 * np.pi * 38 * tt)))) * (0.6 + 0.4 * np.sin(2 * np.pi * 0.7 * tt) ** 2)+add(amb, fade(lp(cic, 6500), 0.2, 0.2), 32.4, 0.05, 0.4)+unit = (np.sin(2 * np.pi * 75 * tt) + 0.4 * np.sin(2 * np.pi * 150 * tt)) * (1 + 0.1 * np.sin(2 * np.pi * 4 * tt)) + lp(noise(d), 200) * 0.6+add(amb, fade(unit, 0.3, 0.2), 32.4, 0.035, -0.5)+for e in ev('suck'): x = hp(noise(0.6), 1200) * (t_(0.6) / 0.6) ** 3; add(fx, x, e['t'], 0.3)+for e in ev('pop'): add(fx, sfx.pop(), e['t'], 0.28)++# ---------------- the charger: a faint switching whine, AC two octaves up, smoothed at the bridge ----------------+d = PULL0 - 34.6; tt = t_(d); whine = np.sin(2 * np.pi * 7800 * tt) * (0.7 + 0.3 * np.sin(2 * np.pi * 3 * tt)); add(amb, fade(whine, 0.3, 0.6), 34.6, 0.004)+ac_tone(35.0, T_DB, 67, 100 / 60 * 4, 0.06)+for e in ev('smooth'):+ if e['n'] == 2: add(fx, fade(bp(noise(0.25), 1500, 9000) * np.exp(-t_(0.25) / 0.05)), e['t'], 0.06)+d = PULL0 + 0.4 - T_DB; x = tone(67, d, 0.12) * np.minimum(1, t_(d) / 0.05); add(mus, fade(x, 0.005, 0.4), T_DB, 0.06)+# the verdict: a low tone (the station) under the high one (the charger); "=" lands a chord+d = PULL0 + 0.4 - 42.2; x = (tone(31, d, 0.1) * 0.4 + tone(43, d, 0.15) * 0.8) * np.minimum(1, t_(d) / 0.8); add(mus, fade(x, 0.05, 0.4), 42.2, 0.10)+for e in ev('equal'):+ t0 = e['t']; add(mus, pad([43, 55, 59, 62, 67, 71, 74], 3.8, 0.04, 2.0, 2600), t0, 0.16)+ add(mus, bell(79, 3.0, 2.0, 1.0), t0, 0.06, -0.3); add(mus, bell(86, 3.0, 2.0, 0.8), t0, 0.05, 0.3)++# ---------------- the pull-out and the end ----------------+for e in ev('pullout'):+ add(fx, sfx.whoosh(1.8) * 0.8, e['t'], 0.14); add(mus, pad([43, 50, 55, 59, 62], DUR - e['t'], 0.8, 2.5, 1700), e['t'], 0.13)+ d = 2.4; tt = t_(d); add(amb, fade(lp(noise(d), 800) * np.sin(np.pi * tt / d), 0.3, 0.3), e['t'] + 0.4, 0.05, -0.6)+ add(amb, fade(bp(noise(d), 4200, 7000) * np.sin(np.pi * tt / d) * 0.6, 0.3, 0.3), e['t'] + 0.6, 0.02, 0.6)+for e in ev('final'): add(fx, hp(sub_hit(2.2, 70, 31), 40), e['t'], 0.26); add(mus, bell(55, 3.5, 3.5, 1.6), e['t'], 0.10); add(mus, bell(67, 3.0, 2.0, 1.0), e['t'], 0.06)+for e in ev('sign'): add(mus, glock(79, 2.0), e['t'], 0.05, 0.2)+d = DUR - PULL0; x = hum(d, 1.0) * np.minimum(1, t_(d) / 1.0); add(amb, fade(x, 0.2, 1.5), PULL0, 0.03)++# ---------------- plotting: tiny scratchy grains while silkscreen draws ----------------+def plotter(d):+ tt = t_(d); gr = (rng.random(len(tt)) > 0.9965).astype(float)+ return bp(lp(gr, 9000) + noise(d) * 0.02, 2500, 7500) * np.minimum(1, tt / 0.02) * np.minimum(1, (d - tt) / 0.04)+for e in ev('plot'): add(fx, plotter(e['d'] + 0.05), e['t'], 0.035 if e.get('big') else 0.02, 0.15)++# ---------------- the voice ----------------+import soxr # noqa: E402+vo = buf(); vo_env = np.zeros(N)+for e in ev('vo'):+ x, sr = sf.read(os.path.join(HERE, VODIR, e['id'] + '.wav'), dtype='float32')+ if x.ndim > 1: x = x.mean(1)+ if sr != SR: x = soxr.resample(x, sr, SR)+ x = hp(x, 80); x = x / (np.sqrt(np.mean(x ** 2)) + 1e-9) * 0.1+ add(vo, x, e['t'], 1.0, 0.0); a0, b0 = int(e['t'] * SR), min(N, int(e['t'] * SR) + len(x)); vo_env[a0:b0] = 1+from scipy.ndimage import uniform_filter1d # noqa: E402+env = np.clip(uniform_filter1d(vo_env, int(0.3 * SR)) * 1.6, 0, 1)+bed_g = 10 ** (-9.5 * env / 20) # duck the bed so it sits 15–18 dB under the voice+fx_g = 10 ** (-7 * env / 20)++# ---------------- mix ----------------+mix = (mus * 0.9 + amb) * bed_g[:, None] + fx * fx_g[:, None] + vo+for c in range(2): mix[:, c] = lp(hp(mix[:, c], 55) - 0.35 * lp(hp(mix[:, c], 55), 140), 14000)+mix[-int(1.2 * SR):] *= np.linspace(1, 0, int(1.2 * SR))[:, None]+pk = np.abs(mix).max(); mix = mix / pk * 0.5+out = os.path.join(HERE, OUTNAME); sf.write(out, mix.astype(np.float32), SR)+# measure, then set the level to about −16 LUFS with the true peak under −3 dBFS+def measure(path):+ r = subprocess.run(['ffmpeg', '-hide_banner', '-nostats', '-i', path, '-af', 'ebur128=peak=true', '-f', 'null', '-'], capture_output=True, text=True).stderr+ I = float(r.split('Integrated loudness:')[1].split('I:')[1].split('LUFS')[0]); TP = float(r.split('True peak:')[1].split('Peak:')[1].split('dBFS')[0]); return I, TP+raw = mix.copy()+for _ in range(4): # gain into a look-ahead limiter until it reads about −16 LUFS+ I, TP = measure(out)+ raw *= 10 ** ((-16.0 - I) / 20); mix = raw.copy()+ for c in range(2): mix[:, c] = sfx.limit(mix[:, c], 10 ** (-5.0 / 20))+ sf.write(out, mix.astype(np.float32), SR)+I, TP = measure(out)+lo = np.sqrt(np.mean(lp(mix[:, 0], 120) ** 2)) / (np.sqrt(np.mean(mix[:, 0] ** 2)) + 1e-9)+vo_r = np.sqrt(np.mean(vo[vo_env > 0] ** 2)); bed_r = np.sqrt(np.mean((((mus * 0.9 + amb) * bed_g[:, None]))[vo_env > 0] ** 2))+print(f'voice over music under the voice: {20 * np.log10(vo_r / bed_r):.1f} dB')+print(f'{OUTNAME} {len(mix) / SR:.2f}s integrated {I:.1f} LUFS true peak {TP:.1f} dBTP low end (<120 Hz) {20 * np.log10(lo):.1f} dB vs full')diff --git a/styles/circuit-board/demo/build.sh b/styles/circuit-board/demo/build.shnew file mode 100644index 0000000..d9e42ae--- /dev/null+++ b/styles/circuit-board/demo/build.sh@@ -0,0 +1,52 @@+#!/bin/sh+# One command: 《七毫秒》 Seven Milliseconds (Circuit Board demo)+# sh styles/circuit-board/demo/build.sh Chinese voice (the library demo): circuit-board.mp4+# sh styles/circuit-board/demo/build.sh en English voice, same picture and subtitles: circuit-board-en.mp4+# Steps: subtitle font, voice + speech check, events, score + mix, picture, master, subtitles (.srt), reading-time check, stills.+# The board's lettering is drawn in code; only the subtitle bar uses a font file (Noto Sans SC, OFL), downloaded from+# github.com/google/fonts in a fresh clone and cut down by tools/subset.py. The voice is Microsoft edge-tts (online).+set -e+HERE=$(cd "$(dirname "$0")" && pwd) # .../<slug>/demo+FILM=$(cd "$HERE/.." && pwd) # .../<slug>+LIB=${LIB:-$(cd "$HERE/../../.." && pwd)} # styles/<slug>/demo -> library root+export LIB+[ -f "$LIB/core/render/video.mjs" ] || { echo "set LIB to the library folder"; exit 1; }+PY="$LIB/.venv/bin/python"+NAME=circuit-board+LANG_=${1:-zh}+FPS=30+FRAME=3.0 # the dam, every unit lit, title printed: poster and gallery still (no subtitles)+cd "$LIB"++# subtitle font (gitignored): Noto Sans SC variable -> weight 500, only the characters the subtitles use+GF=https://github.com/google/fonts/raw/main/ofl+[ -f "$HERE/tools/NotoSansSC-VF.ttf" ] || curl -sfL -o "$HERE/tools/NotoSansSC-VF.ttf" "$GF/notosanssc/NotoSansSC%5Bwght%5D.ttf"+"$PY" -I "$HERE/tools/subset.py" "$HERE"++# voice: Chinese zh-CN-XiaoxiaoNeural +20% (voice/), English en-US-AvaNeural +10% with per-line rates (voice_en/); every line checked by Whisper+"$PY" core/tts/tts_zh.py "$HERE/voice/lines.json" "$HERE/voice" --voice zh-CN-XiaoxiaoNeural --rate +20%+"$PY" core/tts/asr_check.py "$HERE/voice/lines.json" "$HERE/voice" --lang zh+if [ "$LANG_" = en ]; then+ "$PY" core/tts/tts_zh.py "$HERE/voice_en/lines.json" "$HERE/voice_en" --voice en-US-AvaNeural --rate +10%+ "$PY" core/tts/asr_check.py "$HERE/voice_en/lines.json" "$HERE/voice_en" --lang en+fi++# events from the picture, then the score and effects under the voice (mix.wav / mix_en.wav, about -16 LUFS before the master)+node core/render/events.mjs "$HERE"+if [ "$LANG_" = en ]; then "$PY" "$HERE/audio.py" en; MIX="$HERE/mix_en.wav"; OUT="$FILM/$NAME-en.mp4"+else "$PY" "$HERE/audio.py"; MIX="$HERE/mix.wav"; OUT="$FILM/$NAME.mp4"; fi++# picture (subtitles are drawn by the page) and master (mux.sh brings the mix to -14 LUFS and adds a light grain)+node core/render/video.mjs "$HERE" --fps $FPS --workers 3 --out "$HERE/out/video.mp4"+sh core/render/mux.sh "$HERE/out/video.mp4" "$MIX" "$OUT" $FPS 1+python3 "$HERE/tools/srt.py" "$HERE" "$FILM/$NAME.srt"++# reading time of every word printed on the boards (window.TEXTS; the subtitle bar follows the voice, see DEMO.md)+mkdir -p "$HERE/out"+node core/render/readcheck.mjs "$HERE" > "$HERE/out/readcheck.txt" && echo "readcheck ok" || { tail -20 "$HERE/out/readcheck.txt"; exit 1; }++# poster and the gallery style frame, rendered without the subtitle bar+node core/render/still.mjs "$HERE" $FRAME --q nosub=1 --out "$HERE/out/still" --prefix p_+cp "$HERE/out/still/p_$FRAME.jpg" "$FILM/poster.jpg"+mkdir -p "$HERE/stills"; cp "$HERE/out/still/p_$FRAME.jpg" "$HERE/stills/styleframe.jpg"+echo "done: $OUT"diff --git a/styles/circuit-board/demo/data/subs_en.json b/styles/circuit-board/demo/data/subs_en.jsonnew file mode 100644index 0000000..7a28310--- /dev/null+++ b/styles/circuit-board/demo/data/subs_en.json@@ -0,0 +1,13 @@+[+ ["v01", "Power made deep in the mountains of Sichuan reaches Jiangsu, 2,000 km away, in just 7 milliseconds."],+ ["v02", "The electricity in our homes swings back and forth as it flows. It's called alternating current, AC."],+ ["v03", "Sent that far as it is, a lot of it would simply be lost on the way."],+ ["v04", "So first it goes through a converter station and becomes direct current, DC, flowing one way only."],+ ["v05", "Then it races along this line, more than 2,000 km long, all the way to Jiangsu."],+ ["v06", "The whole trip takes 7 milliseconds, less than the blink of an eye."],+ ["v07", "At the end it's turned back into AC, stepped down level by level, and sent to the socket in your wall."],+ ["v08", "Plug in your phone charger, and inside it a tiny part called a bridge rectifier turns the AC back into DC."],+ ["v09", "Believe it or not, it works on the same circuit principle as the giant, storeys tall, in the converter station."],+ ["v10", "Only the station's power is a full 400 million times that of this little charger."],+ ["v11", "Every bar of charge on your phone came this far, across mountains and rivers."]+]diff --git a/styles/circuit-board/demo/events.json b/styles/circuit-board/demo/events.jsonnew file mode 100644index 0000000..9a4dfaa--- /dev/null+++ b/styles/circuit-board/demo/events.json@@ -0,0 +1 @@+{"dur":60,"ev":[{"t":0,"type":"water"},{"t":0,"type":"gen","i":0},{"t":0.15,"type":"gen","i":1},{"t":0.3,"type":"gen","i":2},{"t":0.4,"type":"vo","id":"v01","d":4.881},{"t":0.45,"type":"gen","i":3},{"t":0.6,"type":"gen","i":4},{"t":0.6,"type":"plot","d":0.7,"big":true},{"t":0.75,"type":"gen","i":5},{"t":0.9,"type":"gen","i":6},{"t":0.95,"type":"plot","d":0.6,"big":false},{"t":1.05,"type":"gen","i":7},{"t":1.2,"type":"gen","i":8},{"t":1.35,"type":"gen","i":9},{"t":1.5,"type":"gen","i":10},{"t":1.65,"type":"gen","i":11},{"t":1.8,"type":"gen","i":12},{"t":1.95,"type":"gen","i":13},{"t":2.1,"type":"gen","i":14},{"t":2.25,"type":"gen","i":15},{"t":4.7,"type":"hum"},{"t":5.58,"type":"vo","id":"v02","d":4.342},{"t":6.4,"type":"plot","d":0.5,"big":false},{"t":6.6,"type":"plot","d":0.3,"big":false},{"t":10.1,"type":"cut","i":0},{"t":10.22,"type":"vo","id":"v03","d":4.028},{"t":14.4,"type":"cut","i":1},{"t":14.55,"type":"vo","id":"v04","d":4.391},{"t":14.6,"type":"plot","d":0.5,"big":false},{"t":14.8,"type":"plot","d":0.3,"big":false},{"t":15.3,"type":"plot","d":0.6,"big":false},{"t":15.5,"type":"plot","d":0.5,"big":false},{"t":16.3,"type":"smooth","n":0},{"t":16.7,"type":"plot","d":0.5,"big":false},{"t":16.85,"type":"plot","d":0.3,"big":false},{"t":18.75,"type":"whip"},{"t":19.1,"type":"plot","d":0.4,"big":false},{"t":19.24,"type":"vo","id":"v05","d":3.987},{"t":19.3,"type":"plot","d":0.35,"big":false},{"t":19.59,"type":"km"},{"t":20.421,"type":"km"},{"t":20.5,"type":"plot","d":0.6,"big":false},{"t":20.6,"type":"plot","d":0.4,"big":false},{"t":20.7,"type":"plot","d":0.4,"big":false},{"t":20.8,"type":"plot","d":0.35,"big":false},{"t":21.654,"type":"km"},{"t":23,"type":"impact"},{"t":23.5,"type":"plot","d":0.5,"big":false},{"t":23.53,"type":"vo","id":"v06","d":3.317},{"t":23.7,"type":"plot","d":0.4,"big":false},{"t":24,"type":"plot","d":0.45,"big":true},{"t":24,"type":"bell","n":91},{"t":24.2,"type":"plot","d":0.3,"big":false},{"t":27.15,"type":"vo","id":"v07","d":6.753},{"t":27.2,"type":"plot","d":0.45,"big":false},{"t":27.35,"type":"plot","d":0.3,"big":false},{"t":27.4,"type":"chop"},{"t":29.6,"type":"plot","d":0.35,"big":false},{"t":29.6,"type":"step","i":0},{"t":29.7,"type":"plot","d":0.3,"big":false},{"t":30.3,"type":"step","i":1},{"t":31,"type":"step","i":2},{"t":31.7,"type":"step","i":3},{"t":32.4,"type":"outside"},{"t":34,"type":"suck"},{"t":34.2,"type":"vo","id":"v08","d":7.743},{"t":34.6,"type":"pop"},{"t":35.3,"type":"plot","d":0.5,"big":false},{"t":35.45,"type":"plot","d":0.35,"big":false},{"t":38.5,"type":"plot","d":0.45,"big":false},{"t":38.65,"type":"plot","d":0.4,"big":false},{"t":39.4,"type":"smooth","n":2},{"t":39.9,"type":"plot","d":0.45,"big":false},{"t":40.05,"type":"plot","d":0.35,"big":false},{"t":42.2,"type":"still"},{"t":42.24,"type":"vo","id":"v09","d":5.847},{"t":42.9,"type":"plot","d":0.45,"big":false},{"t":43.05,"type":"plot","d":0.4,"big":false},{"t":47.6,"type":"plot","d":0.25,"big":true},{"t":47.6,"type":"equal"},{"t":47.7,"type":"plot","d":0.6,"big":true},{"t":47.9,"type":"plot","d":0.4,"big":false},{"t":48.39,"type":"vo","id":"v10","d":4.362},{"t":49.4,"type":"plot","d":0.55,"big":true},{"t":49.6,"type":"plot","d":0.4,"big":false},{"t":52.9,"type":"pullout"},{"t":53.05,"type":"vo","id":"v11","d":3.957},{"t":54.4,"type":"plot","d":0.8,"big":false},{"t":54.8,"type":"plot","d":0.8,"big":true},{"t":54.8,"type":"final"},{"t":55.3,"type":"plot","d":0.6,"big":false},{"t":56,"type":"plot","d":0.7,"big":false},{"t":56,"type":"sign"},{"t":60,"type":"end"}]}\ No newline at end of filediff --git a/styles/circuit-board/demo/fonts/OFL-NotoSansSC.txt b/styles/circuit-board/demo/fonts/OFL-NotoSansSC.txtnew file mode 100644index 0000000..1c9f432--- /dev/null+++ b/styles/circuit-board/demo/fonts/OFL-NotoSansSC.txt@@ -0,0 +1,93 @@+Copyright 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'++This Font Software is licensed under the SIL Open Font License, Version 1.1.+This license is copied below, and is also available with a FAQ at:+https://scripts.sil.org/OFL+++-----------------------------------------------------------+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007+-----------------------------------------------------------++PREAMBLE+The goals of the Open Font License (OFL) are to stimulate worldwide+development of collaborative font projects, to support the font creation+efforts of academic and linguistic communities, and to provide a free and+open framework in which fonts may be shared and improved in partnership+with others.++The OFL allows the licensed fonts to be used, studied, modified and+redistributed freely as long as they are not sold by themselves. The+fonts, including any derivative works, can be bundled, embedded,+redistributed and/or sold with any software provided that any reserved+names are not used by derivative works. The fonts and derivatives,+however, cannot be released under any other type of license. The+requirement for fonts to remain under this license does not apply+to any document created using the fonts or their derivatives.++DEFINITIONS+"Font Software" refers to the set of files released by the Copyright+Holder(s) under this license and clearly marked as such. This may+include source files, build scripts and documentation.++"Reserved Font Name" refers to any names specified as such after the+copyright statement(s).++"Original Version" refers to the collection of Font Software components as+distributed by the Copyright Holder(s).++"Modified Version" refers to any derivative made by adding to, deleting,+or substituting -- in part or in whole -- any of the components of the+Original Version, by changing formats or by porting the Font Software to a+new environment.++"Author" refers to any designer, engineer, programmer, technical+writer or other person who contributed to the Font Software.++PERMISSION & CONDITIONS+Permission is hereby granted, free of charge, to any person obtaining+a copy of the Font Software, to use, study, copy, merge, embed, modify,+redistribute, and sell modified and unmodified copies of the Font+Software, subject to the following conditions:++1) Neither the Font Software nor any of its individual components,+in Original or Modified Versions, may be sold by itself.++2) Original or Modified Versions of the Font Software may be bundled,+redistributed and/or sold with any software, provided that each copy+contains the above copyright notice and this license. These can be+included either as stand-alone text files, human-readable headers or+in the appropriate machine-readable metadata fields within text or+binary files as long as those fields can be easily viewed by the user.++3) No Modified Version of the Font Software may use the Reserved Font+Name(s) unless explicit written permission is granted by the corresponding+Copyright Holder. This restriction only applies to the primary font name as+presented to the users.++4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font+Software shall not be used to promote, endorse or advertise any+Modified Version, except to acknowledge the contribution(s) of the+Copyright Holder(s) and the Author(s) or with their explicit written+permission.++5) The Font Software, modified or unmodified, in part or in whole,+must be distributed entirely under this license, and must not be+distributed under any other license. The requirement for fonts to+remain under this license does not apply to any document created+using the Font Software.++TERMINATION+This license becomes null and void if any of the above conditions are+not met.++DISCLAIMER+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM+OTHER DEALINGS IN THE FONT SOFTWARE.diff --git a/styles/circuit-board/demo/index.html b/styles/circuit-board/demo/index.htmlnew file mode 100644index 0000000..0ae132f--- /dev/null+++ b/styles/circuit-board/demo/index.html@@ -0,0 +1,6 @@+<!doctype html>+<html><head><meta charset="utf-8"><title>Seven Milliseconds</title>+<style>html,body{margin:0;background:#000;overflow:hidden}canvas{display:block;width:100vw;height:100vh}</style></head>+<body><canvas id="c" width="1920" height="1080"></canvas>+<script type="module" src="src/main.js"></script>+</body></html>diff --git a/styles/circuit-board/demo/src/charger.js b/styles/circuit-board/demo/src/charger.jsnew file mode 100644index 0000000..ed6a616--- /dev/null+++ b/styles/circuit-board/demo/src/charger.js@@ -0,0 +1,97 @@+// The charger board: a 20 W phone charger's primary side, in millimetres. Layout is invented; the chain is the+// common one (fuse -> bridge -> bulk capacitor -> flyback transformer -> USB-C). DB1 uses the same footprint+// as the converter stations on the corridor board, at 4.5/7 of the size.+import { measure } from './geo.js';+import { bridge, chip, ecap, xfmr, ground, box } from './parts.js';++export const BOARD = { x0: -16, y0: -6, x1: 53, y1: 33, r: 1.6, inset: 0.5 };+export const K = 4.5 / 7; // DB1 is the station footprint at this scale (mm per corridor unit)+export const DB1 = bridge([17.5, 14], 7 * K, { id: 'db1', sw: 0.42 * K });+const F1 = chip([8.2, 14], 3.2, 1.1, 1.5, { sw: 0.16 });+const C1 = ecap([35.2, 10.2], 2.7, { sw: 0.14 });+const T1 = xfmr([41.2, 15.4], 6.4, 7.2, 4, { sw: 0.14 });+const U1 = chip([35.6, 18.6], 2.4, 0.7, 0.9, { sw: 0.12 });+const C2 = chip([43.2, 10.6], 1.8, 0.8, 1.1, { sw: 0.12 });+export const LPAD = [3, 14], NPAD = [3, 22];+export const VIA_N = [DB1.R[0] + 3.2 * K, DB1.R[1]];+export const USB = [0, 1, 2, 3, 4, 5].map(i => ({ x: 51.4, y: 20.6 + i * 1.2 + (i > 2 ? 1.6 : 0), w: 1.8, h: 0.62, shape: 'rect', r: 0.12, id: 'usb' + i }));++const tr = (id, pts, w, net, layer) => ({ id, pts, w, net, layer: layer || 'top' });+export const TRACES = [+ tr('L', [LPAD, F1.a], 0.9, 'ac'),+ tr('L2', [F1.b, DB1.L], 0.9, 'ac'),+ tr('N', [NPAD, [8, NPAD[1]], [11, NPAD[1] + 3], [VIA_N[0] + 1.4, NPAD[1] + 3], [VIA_N[0] + 1.4, VIA_N[1] + 1.4], [VIA_N[0], VIA_N[1]]], 0.9, 'ac', 'bottom'),+ tr('ret', [DB1.R, VIA_N], 0.7, 'ret'),+ tr('plus', [DB1.T, [30.6, DB1.T[1]], [C1.plus[0], C1.plus[1] - 0.7], [C1.plus[0], C1.plus[1]]], 1.0, 'dc'),+ tr('minus', [DB1.B, [32.6, DB1.B[1]], [36.3, 14.8], [C1.minus[0], 14.8], C1.minus], 1.0, 'dc'),+ tr('pri', [C1.plus, [C1.plus[0], 7.4], [T1.pin(-1, 0)[0], 7.4], T1.pin(-1, 0)], 0.8, 'dc'),+ tr('sw', [T1.pin(-1, 3), [U1.b[0] + 0.8, T1.pin(-1, 3)[1]], [U1.b[0] + 0.8, U1.b[1]], U1.b], 0.5, 'dc'),+ tr('sec', [T1.pin(1, 0), [C2.a[0] - 1, T1.pin(1, 0)[1]], [C2.a[0] - 1, C2.a[1]], C2.a], 0.6, 'dc'),+ tr('vbus', [C2.b, [46.8, C2.b[1]], [46.8, USB[0].y - 1.6], [48.4, USB[0].y], [USB[0].x, USB[0].y]], 0.6, 'dc'),+].map(t => ({ ...t, m: measure(t.pts) }));+export const byId = id => TRACES.find(t => t.id === id);++export const PADS = [+ { x: LPAD[0], y: LPAD[1], r: 1.25, shape: 'round', hole: 0.55, id: 'L' }, { x: NPAD[0], y: NPAD[1], r: 1.25, shape: 'round', hole: 0.55, id: 'N' },+ ...F1.pads, ...DB1.pads, ...C1.pads, ...T1.pads, ...U1.pads, ...C2.pads, ...USB,+];+export const VIAS = [[...VIA_N, 0.55, 0.25]];+export const KEEP = [...F1.keep, ...DB1.keep, ...C1.keep, ...T1.keep, ...U1.keep, ...C2.keep, { rect: [50.2, 19.8, 53, 28.6] }];+export const SILK = [+ ...DB1.silk, ...F1.silk, ...C1.silk, ...T1.silk, ...U1.silk, ...C2.silk,+ { circle: [LPAD[0], LPAD[1], 1.9], w: 0.16 }, { circle: [NPAD[0], NPAD[1], 1.9], w: 0.16 },+ { pts: box(49.7, 19.8, 52.4, 28.6), w: 0.14 },+];+// Detail A: the corridor board shown through a round window, Butuo's bridge at DB1's size+export const BUBBLE = { c: [38.4, 13.0], r: 8.0, at: [38.4, 14] }; // `at` = where Butuo's centre lands+export const LABELS = [+ { id: 'chg', text: '充电器', x: -12.5, y: -4.2, cap: 2.4, sw: 0.24, align: 'left' },+ { id: 'chgE', text: 'CHARGER', x: -12.4, y: -0.9, cap: 1.0, sw: 0.18, align: 'left' },+ { id: 'acdc', text: '交流 → 直流', x: DB1.c[0], y: 4.6, cap: 1.1, sw: 0.14, align: 'center' },+ { id: 'acdcE', text: 'AC → DC', x: DB1.c[0], y: 6.3, cap: 0.6, sw: 0.11, align: 'center' },+ { id: 'zlq', text: '整流桥', x: DB1.c[0], y: 21.9, cap: 1.1, sw: 0.14, align: 'center' },+ { id: 'zlqE', text: 'BRIDGE RECTIFIER', x: DB1.c[0], y: 23.6, cap: 0.6, sw: 0.11, align: 'center' },+ { id: 'csV', text: '换流站', x: BUBBLE.c[0], y: 21.9, cap: 1.1, sw: 0.14, align: 'center' },+ { id: 'csVE', text: 'CONVERTER STATION', x: BUBBLE.c[0], y: 23.6, cap: 0.6, sw: 0.11, align: 'center' },+ { id: 'eq', text: '=', x: 26.2, y: 12.1, cap: 3.6, sw: 0.36, align: 'center' },+ { id: 'same', text: '同一个电路原理', x: 27.4, y: 4.6, cap: 1.0, sw: 0.13, align: 'center' },+ { id: 'sameE', text: 'THE SAME CIRCUIT', x: 27.4, y: 6.3, cap: 0.6, sw: 0.11, align: 'center' },+ { id: 'x4', text: '功率差 4 亿倍', x: 27.9, y: 25.1, cap: 1.1, sw: 0.14, align: 'center' },+ { id: 'x4E', text: '400 MILLION × THE POWER', x: 27.9, y: 26.8, cap: 0.6, sw: 0.11, align: 'center' },+];+export const DESIG = [+ { text: 'USB-C · 20 W', x: 48.4, y: 26.9, cap: 0.5, align: 'right' },+ { text: 'L', x: LPAD[0], y: LPAD[1] - 3.5, cap: 0.9, align: 'center' }, { text: 'N', x: NPAD[0], y: NPAD[1] - 3.5, cap: 0.9, align: 'center' },+ { text: 'F1', x: F1.a[0] + 1.6, y: 11.2, cap: 0.8, align: 'center' },+ { text: 'DB1', x: DB1.L[0] - 0.4, y: DB1.T[1] - 0.6, cap: 0.8, align: 'right' },+ { text: 'C1', x: 35.2, y: 13.1, cap: 0.7, align: 'center' },+ { text: 'T1', x: 41.2, y: 19.6, cap: 0.7, align: 'center' },+ { text: 'U1', x: U1.a[0] + 1.2, y: 19.6, cap: 0.6, align: 'center' },+ { text: 'C2', x: C2.a[0] + 0.9, y: 10.4, cap: 0.6, align: 'center' },+];+export const HOLES = [[-14.3, -4.3], [51.3, -4.3], [-14.3, 31.3], [51.3, 31.3]];+export const FIDS = [[6.4, -4.4], [46.6, 31.4]];+export const TITLE = null;+export const CLR = 0.28, VIA_R = 0.3, HOLE_R = 1.1, FID_R = 0.45;+// more of a real charger: a varistor and an X capacitor across the input, the isolation slot under T1,+// a Y capacitor and an optocoupler bridging it, the output diode and capacitor on the secondary side+const RV1 = ecap([7.6, 19.4], 1.5, { sw: 0.12 }), CX1 = chip([12.6, 19.6], 2.6, 0.9, 1.2, { sw: 0.12 });+const CY1 = chip([41.2, 6.2], 3.0, 0.9, 1.2, { sw: 0.12 }), U2 = chip([39.6, 20.2], 3.0, 0.9, 1.3, { sw: 0.12 });+export const SLOTS = [{ pts: [[41.2, 8.4], [41.2, 21.4]], w: 0.7 }];+PADS.push(...RV1.pads, ...CX1.pads, ...CY1.pads, ...U2.pads, { x: 6.4, y: 8.6, r: 0.55, shape: 'round', hole: 0.22, id: 'tp1' }, { x: 3.0, y: 26.6, r: 0.55, shape: 'round', hole: 0.22, id: 'tp2' });+SILK.push(...RV1.silk, ...CX1.silk, ...CY1.silk, ...U2.silk, { circle: [6.4, 8.6, 0.9], w: 0.1 }, { circle: [3.0, 26.6, 0.9], w: 0.1 });+KEEP.push(...RV1.keep, ...CX1.keep, ...CY1.keep, ...U2.keep);+DESIG.push({ text: 'RV1', x: 7.6, y: 21.4, cap: 0.6, align: 'center' }, { text: 'CX1', x: 12.6, y: 21.0, cap: 0.6, align: 'center' }, { text: 'CY1', x: 39.0, y: 5.8, cap: 0.6, align: 'right' },+ { text: 'U2', x: 41.6, y: 18.6, cap: 0.6, align: 'left' },+ { text: 'TP1', x: 7.6, y: 8.2, cap: 0.55, align: 'left' }, { text: 'TP2', x: 4.1, y: 26.3, cap: 0.55, align: 'left' },+ { text: 'PRIMARY', x: 40.6, y: 1.6, cap: 0.5, align: 'right' }, { text: 'SECONDARY', x: 41.8, y: 1.6, cap: 0.5, align: 'left' },+ { text: 'REV B', x: 2.4, y: -3.0, cap: 0.6, align: 'left' });+TRACES.push(...[['mov', [[LPAD[0] + 1.6, 14], [5.4, 14], [5.4, 19.4], [RV1.plus[0], 19.4]], 0.5], ['cx', [[RV1.minus[0], 19.4], [CX1.a[0], 19.6]], 0.5],+].map(([id, pts, w]) => ({ id, pts, w, net: 'sig', m: measure(pts) })));+// the plug: two blade terminals on the left, inside a silkscreened housing, wired to L and N+PADS.push({ x: -8.5, y: 14, w: 6.4, h: 1.9, shape: 'rect', r: 0.3, id: 'pinL' }, { x: -8.5, y: 22, w: 6.4, h: 1.9, shape: 'rect', r: 0.3, id: 'pinN' });+SILK.push({ pts: box(-13.4, 10.6, -2.6, 25.4), w: 0.2 }, { pts: box(-12.6, 11.4, -3.4, 24.6), w: 0.1, dash: [0.5, 0.4] });+KEEP.push({ rect: [-12.2, 12.6, -4.8, 15.4] }, { rect: [-12.2, 20.6, -4.8, 23.4] });+TRACES.push(...[['pL', [[-5.3, 14], [LPAD[0] - 1.3, 14]], 1.1], ['pN', [[-5.3, 22], [NPAD[0] - 1.3, 22]], 1.1]].map(([id, pts, w]) => ({ id, pts, w, net: 'ac', m: measure(pts) })));+DESIG.push({ text: 'AC IN', x: -8, y: 8.6, cap: 0.7, align: 'center' }, { text: 'P1', x: -8, y: 26.2, cap: 0.6, align: 'center' });+export { F1, C1, T1 };diff --git a/styles/circuit-board/demo/src/city.js b/styles/circuit-board/demo/src/city.jsnew file mode 100644index 0000000..f0aefa5--- /dev/null+++ b/styles/circuit-board/demo/src/city.js@@ -0,0 +1,68 @@+// The city module next to Yucheng (a child board of the corridor board), 1 unit = 10 m.+// Streets are bare channels in the copper; buildings are silk footprints holding tiny pads (lit at noon);+// the feed comes in on the left, steps down at T2 (city substation) and T3 (district), and leaves for the street module.+import { measure } from './geo.js';+import { xformer, box } from './parts.js';+import { stepLabel } from './world.js';+import { mulberry } from '/core/lib.js';++export const BOARD = { x0: 0, y0: 0, x1: 1200, y1: 800, r: 6, inset: 1 };+export const CLR = 2.2, VIA_R = 1.6, FENCE_R = 1.2;+const AVE = [230, 470, 700, 930], ROAD = [210, 420, 610], MINX = [115, 350, 585, 815, 1065], MINY = [105, 315, 515, 705];+export const STREETS = [+ ...AVE.map(x => ({ pts: [[x, -10], [x, 810]], w: 9 })), ...ROAD.map(y => ({ pts: [[-10, y], [1210, y]], w: 9 })),+ ...MINX.map(x => ({ pts: [[x, -10], [x, 810]], w: 3.4 })), ...MINY.map(y => ({ pts: [[-10, y], [1210, y]], w: 3.4 })),+];+export const T2 = xformer([200, 160], 60, [6, 3], 1.6);+export const T3 = xformer([390, 360], 12, [7, 3], 0.36);+export const HOUSE_AT = [520, 520], HOUSE_S = 0.01; // the street module (900 x 900 at 10 cm)+const houseIn = [HOUSE_AT[0], HOUSE_AT[1] + 760 * HOUSE_S];+const tr = (id, pts, w, net) => ({ id, pts, w, net });+export const TRACES = [+ tr('in', [[0, 160], T2.inP], 10.7, 'ac'),+ tr('c1', [T2.outP, [330, 160], [330, 360], T3.inP], 5.3, 'ac'),+ tr('c2', [T3.outP, [440, 360], [440, houseIn[1]], houseIn], 0.53, 'ac'),+ // other feeders of the city grid (not lit): along the streets to the other substations+ tr('f1', [[T2.outP[0] + 30, 160], [T2.outP[0] + 30, 260], [760, 260], [760, 160], [850 - 30, 160]], 2.6, 'idle'),+ tr('f2', [[330, 360], [330, 470], [650, 470], [650, 560], [1000, 560], [1000, 500]], 2.6, 'idle'),+ tr('f3', [[330, 260], [180, 260], [180, 660], [250 - 6, 660]], 2.6, 'idle'),+].map(t => ({ ...t, m: measure(t.pts) }));+export const byId = id => TRACES.find(t => t.id === id);+const OTH = [xformer([850, 160], 60, [6, 3], 1.6), xformer([1000, 470], 24, [6, 3], 0.7), xformer([250, 660], 12, [7, 3], 0.36)];+export const PADS = [...T2.pads, ...T3.pads, ...OTH.flatMap(o => o.pads)];+export const SILK = [...T2.silk, ...T3.silk, ...OTH.flatMap(o => o.silk),+ { pts: box(HOUSE_AT[0] - 0.3, HOUSE_AT[1] - 0.3, HOUSE_AT[0] + 9.3, HOUSE_AT[1] + 9.3), w: 0.12 }];+export const KEEP = [...T2.keep, ...T3.keep, ...OTH.flatMap(o => o.keep), { rect: [HOUSE_AT[0] - 0.6, HOUSE_AT[1] - 0.6, HOUSE_AT[0] + 9.6, HOUSE_AT[1] + 9.6] }];+export const VIAS = [];+export const DESIG = [+ { text: 'T4', x: 850, y: 120, cap: 9, align: 'center' }, { text: 'T5', x: 1000, y: 452, cap: 4, align: 'center' }, { text: 'T6', x: 250, y: 650, cap: 2, align: 'center' },+ { text: 'M2', x: HOUSE_AT[0] - 0.6, y: HOUSE_AT[1] + 0.3, cap: 0.9, align: 'right' },+];+export const LABELS = [...stepLabel(T2).map(l => ({ ...l, id: l.id + '2' })), ...stepLabel(T3).map(l => ({ ...l, id: l.id + '3' }))];+// buildings: silk footprints, each a grid of small pads (homes); block interiors seeded, kept clear of the feed and parts+const xs = [0, ...AVE, ...MINX, 1200].sort((a, b) => a - b), ys = [0, ...ROAD, ...MINY, 800].sort((a, b) => a - b);+export const TPADS = [];+const rnd = mulberry(17);+const busy = [[0, 125, 240, 195], [100, 150, 340, 170], [320, 150, 340, 370], [330, 350, 450, 370], [430, 350, 450, 540], [440, 515, 535, 535],+ [HOUSE_AT[0] - 4, HOUSE_AT[1] - 4, HOUSE_AT[0] + 14, HOUSE_AT[1] + 14], [150, 120, 250, 200], [800, 120, 900, 200], [985, 455, 1015, 485], [240, 650, 262, 670],+ [100, 250, 770, 270], [750, 150, 770, 270], [320, 460, 660, 480], [640, 460, 660, 570], [640, 550, 1010, 570], [990, 490, 1010, 570], [170, 250, 190, 670], [170, 650, 250, 670]];+const hit = (x0, y0, x1, y1) => busy.some(b => x0 < b[2] && x1 > b[0] && y0 < b[3] && y1 > b[1]);+for (let i = 0; i < xs.length - 1; i++) for (let j = 0; j < ys.length - 1; j++) {+ const bx0 = xs[i] + 8, bx1 = xs[i + 1] - 8, by0 = ys[j] + 8, by1 = ys[j + 1] - 8;+ let y = by0;+ while (y < by1 - 14) {+ const h = 14 + Math.floor(rnd() * 3) * 6; let x = bx0;+ while (x < bx1 - 12) {+ const w = 12 + Math.floor(rnd() * 4) * 5;+ if (x + w <= bx1 && y + h <= by1 && !hit(x, y, x + w, y + h) && rnd() > 0.12) {+ SILK.push({ pts: box(x, y, x + w, y + h), w: 0.5 });+ KEEP.push({ rect: [x, y, x + w, y + h] });+ const nx = Math.max(1, Math.floor((w - 3) / 4.2)), ny = Math.max(1, Math.floor((h - 3) / 3.6));+ for (let a = 0; a < nx; a++) for (let b = 0; b < ny; b++) TPADS.push({ x: x + 2.4 + a * (w - 4.8) / Math.max(1, nx - 1) - (nx === 1 ? -(w - 4.8) / 2 : 0), y: y + 2.4 + b * (h - 4.8) / Math.max(1, ny - 1) - (ny === 1 ? -(h - 4.8) / 2 : 0), w: 2.6, h: 1.8, lit: rnd() < 0.82 });+ }+ x += w + 4;+ }+ y += h + 4;+ }+}+export const CHILD = { name: 'house', at: HOUSE_AT, s: HOUSE_S };diff --git a/styles/circuit-board/demo/src/font.js b/styles/circuit-board/demo/src/font.jsnew file mode 100644index 0000000..bac8d30--- /dev/null+++ b/styles/circuit-board/demo/src/font.js@@ -0,0 +1,159 @@+import { HANZI } from './hanzi.js';+// "Routed" — a monoline silkscreen stroke font drawn like PCB traces:+// 0/45/90-degree runs, chamfered corners, round caps. Cap height = 10 units, y down.+// Each glyph: { w: advance width (without tracking), s: [[x,y, x,y, ...], ...] strokes }.++const oct = (cx, cy, r) => { // small octagon ring (for %)+ const k = r * 0.4142, p = [];+ [[-k, -r], [k, -r], [r, -k], [r, k], [k, r], [-k, r], [-r, k], [-r, -k], [-k, -r]].forEach(([x, y]) => p.push(cx + x, cy + y));+ return p;+};+const D = 0.01; // zero-length dot (round cap)++export const GLYPHS = {+ 'A': { w: 6, s: [[0, 10, 0, 3, 3, 0, 6, 3, 6, 10], [0, 6.3, 6, 6.3]] },+ 'B': { w: 6, s: [[0, 5, 0, 0, 4.2, 0, 5.7, 1.5, 5.7, 3.5, 4.2, 5, 0, 5], [4.2, 5, 6, 6.8, 6, 8.2, 4.2, 10, 0, 10, 0, 5]] },+ 'C': { w: 6, s: [[6, 0, 2, 0, 0, 2, 0, 8, 2, 10, 6, 10]] },+ 'D': { w: 6, s: [[0, 0, 3.8, 0, 6, 2.2, 6, 7.8, 3.8, 10, 0, 10, 0, 0]] },+ 'E': { w: 5.4, s: [[5.4, 0, 0, 0, 0, 10, 5.4, 10], [0, 5, 4.4, 5]] },+ 'F': { w: 5.4, s: [[5.4, 0, 0, 0, 0, 10], [0, 5, 4.4, 5]] },+ 'G': { w: 6, s: [[6, 0, 2, 0, 0, 2, 0, 8, 2, 10, 6, 10, 6, 5.2, 3.4, 5.2]] },+ 'H': { w: 6, s: [[0, 0, 0, 10], [6, 0, 6, 10], [0, 5, 6, 5]] },+ 'I': { w: 0, s: [[0, 0, 0, 10]] },+ 'J': { w: 5.4, s: [[5.4, 0, 5.4, 8, 3.4, 10, 2, 10, 0, 8]] },+ 'K': { w: 6, s: [[0, 0, 0, 10], [6, 0, 1, 5, 6, 10], [0, 5, 1, 5]] },+ 'L': { w: 5.4, s: [[0, 0, 0, 10, 5.4, 10]] },+ 'M': { w: 8, s: [[0, 10, 0, 0, 4, 4, 8, 0, 8, 10]] },+ 'N': { w: 6, s: [[0, 10, 0, 0, 6, 10, 6, 0]] },+ 'O': { w: 6, s: [[2, 0, 4, 0, 6, 2, 6, 8, 4, 10, 2, 10, 0, 8, 0, 2, 2, 0]] },+ 'P': { w: 6, s: [[0, 10, 0, 0, 4.2, 0, 6, 1.8, 6, 3.8, 4.2, 5.6, 0, 5.6]] },+ 'Q': { w: 6, s: [[2, 0, 4, 0, 6, 2, 6, 8, 4, 10, 2, 10, 0, 8, 0, 2, 2, 0], [3.6, 7.6, 6.4, 10.4]] },+ 'R': { w: 6, s: [[0, 10, 0, 0, 4.2, 0, 6, 1.8, 6, 3.6, 4.2, 5.4, 0, 5.4], [3.8, 5.4, 6, 7.6, 6, 10]] },+ 'S': { w: 6, s: [[6, 0, 1.8, 0, 0, 1.8, 0, 3.2, 1.8, 5, 4.2, 5, 6, 6.8, 6, 8.2, 4.2, 10, 0, 10]] },+ 'T': { w: 6, s: [[0, 0, 6, 0], [3, 0, 3, 10]] },+ 'U': { w: 6, s: [[0, 0, 0, 8, 2, 10, 4, 10, 6, 8, 6, 0]] },+ 'V': { w: 6.4, s: [[0, 0, 3.2, 10, 6.4, 0]] },+ 'W': { w: 8.6, s: [[0, 0, 2.1, 10, 4.3, 3.4, 6.5, 10, 8.6, 0]] },+ 'X': { w: 6, s: [[0, 0, 6, 10], [6, 0, 0, 10]] },+ 'Y': { w: 6, s: [[0, 0, 0, 2, 3, 5, 6, 2, 6, 0], [3, 5, 3, 10]] },+ 'Z': { w: 6, s: [[0, 0, 6, 0, 0, 10, 6, 10]] },+ 'a': { w: 4.8, s: [[0.4, 3.4, 3.4, 3.4, 4.8, 4.8, 4.8, 10], [4.8, 6.4, 1.4, 6.4, 0, 7.8, 0, 8.6, 1.4, 10, 3.4, 10, 4.8, 8.6]] },+ 'b': { w: 4.8, s: [[0, 0, 0, 10, 3.4, 10, 4.8, 8.6, 4.8, 4.8, 3.4, 3.4, 0, 3.4]] },+ 'd': { w: 4.8, s: [[4.8, 0, 4.8, 10, 1.4, 10, 0, 8.6, 0, 4.8, 1.4, 3.4, 4.8, 3.4]] },+ 'e': { w: 4.8, s: [[0, 6.8, 4.8, 6.8, 4.8, 4.8, 3.4, 3.4, 1.4, 3.4, 0, 4.8, 0, 8.6, 1.4, 10, 4.6, 10]] },+ 'l': { w: 1.4, s: [[0, 0, 0, 8.6, 1.4, 10]] },+ 'o': { w: 4.8, s: [[1.4, 3.4, 3.4, 3.4, 4.8, 4.8, 4.8, 8.6, 3.4, 10, 1.4, 10, 0, 8.6, 0, 4.8, 1.4, 3.4]] },+ 'p': { w: 4.8, s: [[0, 13, 0, 3.4, 3.4, 3.4, 4.8, 4.8, 4.8, 8.6, 3.4, 10, 0, 10]] },+ 'u': { w: 4.8, s: [[0, 3.4, 0, 8.6, 1.4, 10, 3.4, 10, 4.8, 8.6], [4.8, 3.4, 4.8, 10]] },+ 'k': { w: 5, s: [[0, 0, 0, 10], [5, 3.4, 0.8, 7.6], [1.6, 6.6, 5, 10]] },+ 'm': { w: 7, s: [[0, 10, 0, 3.4], [0, 4.8, 1.4, 3.4, 2.6, 3.4, 3.5, 4.3, 3.5, 10], [3.5, 4.3, 4.4, 3.4, 5.6, 3.4, 7, 4.8, 7, 10]] },+ 'z': { w: 4.8, s: [[0, 3.4, 4.8, 3.4, 4.8, 4.2, 0, 9, 0, 10, 4.8, 10]] },+ '~': { w: 6.6, s: [[0, 6, 1.4, 4.6, 2.6, 4.6, 4, 6, 5.2, 6, 6.6, 4.6]] },+ '−': { w: 5, s: [[0, 5.4, 5, 5.4]] },+ '±': { w: 6, s: [[0, 4.2, 6, 4.2], [3, 1.2, 3, 7.2], [0, 9.8, 6, 9.8]] },+ 's': { w: 4.8, s: [[4.8, 3.4, 1.4, 3.4, 0, 4.8, 0, 5.4, 1.2, 6.6, 3.6, 6.6, 4.8, 7.8, 4.8, 8.6, 3.4, 10, 0, 10]] },+ '0': { w: 5.6, s: [[2, 0, 3.6, 0, 5.6, 2, 5.6, 8, 3.6, 10, 2, 10, 0, 8, 0, 2, 2, 0]] },+ '1': { w: 2.2, s: [[0, 2.2, 2.2, 0, 2.2, 10]] },+ '2': { w: 5.6, s: [[0, 2, 2, 0, 3.6, 0, 5.6, 2, 5.6, 3.8, 0, 9.4, 0, 10, 5.6, 10]] },+ '3': { w: 5.6, s: [[0, 0, 3.8, 0, 5.6, 1.8, 5.6, 3.2, 3.8, 5, 1.6, 5], [3.8, 5, 5.6, 6.8, 5.6, 8.2, 3.8, 10, 0, 10]] },+ '4': { w: 6, s: [[4.4, 10, 4.4, 0, 0, 4.4, 0, 6.8, 6, 6.8]] },+ '5': { w: 5.6, s: [[5.6, 0, 0, 0, 0, 4.6, 3.8, 4.6, 5.6, 6.4, 5.6, 8.2, 3.8, 10, 0, 10]] },+ '6': { w: 5.6, s: [[5, 0, 2, 0, 0, 2, 0, 8, 2, 10, 3.6, 10, 5.6, 8, 5.6, 6.6, 3.6, 4.6, 0, 4.6]] },+ '7': { w: 5.6, s: [[0, 0, 5.6, 0, 5.6, 1.6, 1.8, 5.4, 1.8, 10]] },+ '8': { w: 5.8, s: [[1.8, 5, 0.4, 3.6, 0.4, 1.6, 2, 0, 3.8, 0, 5.4, 1.6, 5.4, 3.6, 4, 5, 1.8, 5, 0, 6.8, 0, 8.2, 1.8, 10, 4, 10, 5.8, 8.2, 5.8, 6.8, 4, 5]] },+ '9': { w: 5.6, s: [[0.6, 10, 3.6, 10, 5.6, 8, 5.6, 2, 3.6, 0, 2, 0, 0, 2, 0, 3.4, 2, 5.4, 5.6, 5.4]] },+ '.': { w: 0, s: [[0, 10, D, 10]] },+ ',': { w: 0.8, s: [[0.8, 9.4, 0, 11.6]] },+ ':': { w: 0, s: [[0, 3.6, D, 3.6], [0, 10, D, 10]] },+ '·': { w: 0, s: [[0, 5.2, D, 5.2]] },+ '-': { w: 4, s: [[0, 5.4, 4, 5.4]] },+ '–': { w: 6, s: [[0, 5.4, 6, 5.4]] },+ '+': { w: 6, s: [[0, 5.4, 6, 5.4], [3, 2.4, 3, 8.4]] },+ '×': { w: 5, s: [[0, 3, 5, 8], [5, 3, 0, 8]] },+ '=': { w: 5, s: [[0, 3.8, 5, 3.8], [0, 7, 5, 7]] },+ '≈': { w: 6, s: [[0, 4.6, 1.4, 3.2, 2.4, 3.2, 3.6, 4.4, 4.6, 4.4, 6, 3.0], [0, 8.0, 1.4, 6.6, 2.4, 6.6, 3.6, 7.8, 4.6, 7.8, 6, 6.4]] },+ '%': { w: 6.6, s: [[0.4, 10, 6.2, 0], oct(1.5, 1.8, 1.5), oct(5.1, 8.2, 1.5)] },+ '/': { w: 5, s: [[0, 10, 5, 0]] },+ '(': { w: 2, s: [[2, -1, 0, 1, 0, 9, 2, 11]] },+ ')': { w: 2, s: [[0, -1, 2, 1, 2, 9, 0, 11]] },+ '?': { w: 5.6, s: [[0, 2, 2, 0, 3.6, 0, 5.6, 2, 5.6, 3.6, 2.8, 6.4, 2.8, 7.4], [2.8, 10, 2.8 + D, 10]] },+ '!': { w: 0, s: [[0, 0, 0, 7], [0, 10, D, 10]] },+ "'": { w: 0, s: [[0, 0, 0, 2.8]] },+ '→': { w: 9, s: [[0, 5, 9, 5], [5.4, 1.4, 9, 5, 5.4, 8.6]] },+ '#': { w: 6, s: [[1.6, 0, 1.6, 10], [4.4, 0, 4.4, 10], [0, 3.4, 6, 3.4], [0, 6.6, 6, 6.6]] },+};++export const TRACK = 3.1; // gap added after each glyph (units of cap/10)+export const SPACE = 4.6;+export const HZ_ADV = 14.2; // hanzi advance: 12-unit box + gap++// Hanzi strokes come in a 12-unit box; shift to y = -1..11 and chamfer every 90-degree corner like a routed trace.+const CH = 0.75;+function chamfer(s) {+ const pts = []; for (let i = 0; i < s.length; i += 2) pts.push([s[i], s[i + 1] - 1]);+ const closed = pts.length > 3 && Math.hypot(pts[0][0] - pts[pts.length - 1][0], pts[0][1] - pts[pts.length - 1][1]) < 1e-6;+ const n = pts.length, out = [];+ const corner = (a, b, c) => {+ const d1 = [b[0] - a[0], b[1] - a[1]], d2 = [c[0] - b[0], c[1] - b[1]], l1 = Math.hypot(...d1), l2 = Math.hypot(...d2);+ if (l1 < 2 * CH || l2 < 2 * CH) return null;+ if (Math.abs(d1[0] * d2[0] + d1[1] * d2[1]) > 1e-6 * l1 * l2) return null; // only right angles+ return [[b[0] - d1[0] / l1 * CH, b[1] - d1[1] / l1 * CH], [b[0] + d2[0] / l2 * CH, b[1] + d2[1] / l2 * CH]];+ };+ for (let i = 0; i < n; i++) {+ const b = pts[i];+ let a = pts[i - 1], c = pts[i + 1];+ if (closed && i === 0) a = pts[n - 2];+ if (closed && i === n - 1) c = pts[1];+ const k = a && c ? corner(a, b, c) : null;+ if (k) out.push(...k); else out.push(b);+ }+ if (closed) { out[out.length - 1] = out[0]; }+ return out.flat();+}+const HZ = {};+for (const [ch, strokes] of Object.entries(HANZI)) HZ[ch] = { w: 12, s: strokes.map(chamfer) };+export const isHanzi = ch => !!HZ[ch];++// Layout a string: returns { strokes: [[x,y,...] in units], width, len }+const cache = new Map();+export function layout(str) {+ if (cache.has(str)) return cache.get(str);+ let x = 0; const strokes = [];+ for (const ch of str) {+ if (ch === ' ') { x += SPACE; continue; }+ const hz = HZ[ch], g = hz || GLYPHS[ch] || GLYPHS['?'];+ for (const s of g.s) { const o = new Array(s.length); for (let i = 0; i < s.length; i += 2) { o[i] = s[i] + x; o[i + 1] = s[i + 1]; } strokes.push(o); }+ x += hz ? HZ_ADV : g.w + TRACK;+ }+ const last = [...str].pop();+ const width = Math.max(0, x - (HZ[last] ? HZ_ADV - 12 : TRACK));+ let len = 0;+ for (const s of strokes) for (let i = 2; i < s.length; i += 2) len += Math.hypot(s[i] - s[i - 2], s[i + 1] - s[i - 1]);+ const r = { strokes, width, len };+ cache.set(str, r); return r;+}+export const textWidth = (str, cap) => layout(str).width * cap / 10;++// Draw text with cap height `cap` (in the ctx's current units), left/centre/right aligned at baseline-top (x, y = top of caps).+// opts: { weight (stroke width as fraction of cap, default .15), align, progress (0..1 plotting), color }+export function drawText(ctx, str, x, y, cap, opts = {}) {+ const L = layout(str), k = cap / 10, w = opts.sw ?? (opts.weight ?? 0.15) * cap;+ const ax = opts.align === 'center' ? -L.width * k / 2 : opts.align === 'right' ? -L.width * k : 0;+ const prog = opts.progress ?? 1;+ if (prog <= 0) return L.width * k;+ let budget = prog >= 1 ? Infinity : prog * L.len;+ ctx.lineWidth = w; ctx.lineCap = 'round'; ctx.lineJoin = 'round';+ if (opts.color) ctx.strokeStyle = opts.color;+ ctx.beginPath();+ for (const s of L.strokes) {+ if (budget <= 0) break;+ ctx.moveTo(x + ax + s[0] * k, y + s[1] * k);+ for (let i = 2; i < s.length; i += 2) {+ const sl = Math.hypot(s[i] - s[i - 2], s[i + 1] - s[i - 1]);+ if (sl <= budget) { ctx.lineTo(x + ax + s[i] * k, y + s[i + 1] * k); budget -= sl; }+ else { const f = budget / sl; ctx.lineTo(x + ax + (s[i - 2] + (s[i] - s[i - 2]) * f) * k, y + (s[i - 1] + (s[i + 1] - s[i - 1]) * f) * k); budget = 0; break; }+ }+ }+ ctx.stroke();+ return L.width * k;+}diff --git a/styles/circuit-board/demo/src/geo.js b/styles/circuit-board/demo/src/geo.jsnew file mode 100644index 0000000..fa8e3a4--- /dev/null+++ b/styles/circuit-board/demo/src/geo.js@@ -0,0 +1,74 @@+// Board projection for the Yangtze corridor: 1 unit is about 1 km (equirectangular at 30 deg N).+export const P = (lon, lat) => [(lon - 100.6) * 96, (34.2 - lat) * 111];++// Route through waypoints with PCB-style 45° geometry. Each waypoint after the first may carry a mode:+// 'd' = diagonal first, 's' = straight first (default 's'). Points are [x,y] or [x,y,mode].+export function octi(pts) {+ const out = [[pts[0][0], pts[0][1]]];+ for (let i = 1; i < pts.length; i++) {+ const a = out[out.length - 1], b = pts[i], mode = b[2] || 's';+ const dx = b[0] - a[0], dy = b[1] - a[1], ax = Math.abs(dx), ay = Math.abs(dy);+ if (Math.min(ax, ay) > 1e-6 && Math.abs(ax - ay) > 1e-6) {+ const d = Math.min(ax, ay), sx = Math.sign(dx), sy = Math.sign(dy);+ if (mode === 'd') out.push([a[0] + sx * d, a[1] + sy * d]);+ else out.push(ax > ay ? [a[0] + dx - sx * d, a[1]] : [a[0], a[1] + dy - sy * d]);+ }+ out.push([b[0], b[1]]);+ }+ return dedupe(out);+}+function dedupe(p) { const o = [p[0]]; for (let i = 1; i < p.length; i++) if (Math.hypot(p[i][0] - o[o.length - 1][0], p[i][1] - o[o.length - 1][1]) > 1e-6) o.push(p[i]); return o; }++// Parallel offset of an open polyline (mitred). d > 0 = to the left of travel direction (screen: y down).+export function offset(pts, d) {+ const n = pts.length, segs = [];+ for (let i = 0; i < n - 1; i++) {+ const [x0, y0] = pts[i], [x1, y1] = pts[i + 1], L = Math.hypot(x1 - x0, y1 - y0);+ const nx = (y1 - y0) / L, ny = -(x1 - x0) / L;+ segs.push([x0 + nx * d, y0 + ny * d, x1 + nx * d, y1 + ny * d]);+ }+ const out = [[segs[0][0], segs[0][1]]];+ for (let i = 0; i < segs.length - 1; i++) {+ const p = inter(segs[i], segs[i + 1]); out.push(p || [segs[i][2], segs[i][3]]);+ }+ const l = segs[segs.length - 1]; out.push([l[2], l[3]]);+ return out;+}+function inter(a, b) {+ const [x1, y1, x2, y2] = a, [x3, y3, x4, y4] = b;+ const den = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);+ if (Math.abs(den) < 1e-9) return null;+ const t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / den;+ return [x1 + t * (x2 - x1), y1 + t * (y2 - y1)];+}++// Polyline measuring+export function measure(pts) {+ const cum = [0];+ for (let i = 1; i < pts.length; i++) cum.push(cum[i - 1] + Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]));+ return { pts, cum, len: cum[cum.length - 1] };+}+export function at(m, s) {+ const { pts, cum } = m; s = Math.max(0, Math.min(m.len, s));+ let i = 1; while (i < cum.length - 1 && cum[i] < s) i++;+ const f = (s - cum[i - 1]) / ((cum[i] - cum[i - 1]) || 1);+ return [pts[i - 1][0] + (pts[i][0] - pts[i - 1][0]) * f, pts[i - 1][1] + (pts[i][1] - pts[i - 1][1]) * f];+}+// sub-polyline between arc lengths s0..s1+export function sub(m, s0, s1) {+ s0 = Math.max(0, s0); s1 = Math.min(m.len, s1); if (s1 <= s0) return [];+ const out = [at(m, s0)];+ for (let i = 1; i < m.pts.length - 1; i++) if (m.cum[i] > s0 && m.cum[i] < s1) out.push(m.pts[i]);+ out.push(at(m, s1)); return out;+}+// Trim the ends of a polyline by a0 (start) and a1 (end)+export function trim(pts, a0, a1) { const m = measure(pts); return sub(m, a0, m.len - a1); }++// octilinear closed outline through waypoints+export function octiClosed(pts) { const o = octi([...pts, [pts[0][0], pts[0][1], pts[0][2]]]); o.pop(); return o; }+// point and unit tangent at arc length s+export function frameAt(m, s) {+ const p = at(m, s), q = at(m, Math.min(m.len, s + 0.5)), r = at(m, Math.max(0, s - 0.5));+ const dx = q[0] - r[0], dy = q[1] - r[1], L = Math.hypot(dx, dy) || 1;+ return { p, t: [dx / L, dy / L], n: [dy / L, -dx / L] };+}diff --git a/styles/circuit-board/demo/src/hanzi.js b/styles/circuit-board/demo/src/hanzi.jsnew file mode 100644index 0000000..c572ead--- /dev/null+++ b/styles/circuit-board/demo/src/hanzi.js@@ -0,0 +1,77 @@+// Hanzi for "Routed": hand-routed single-line glyphs, drawn like PCB traces (0/45/90-degree runs only).+// Box: x 0..12, y 0..12 (y down). font.js maps the box to y = -1..11 against a Latin cap height of 10,+// and cuts 90-degree corners with a small chamfer at layout time. One array per stroke: [x,y, x,y, ...].+// Original drawings for this film (not traced from any font).+const R = (x0, y0, x1, y1) => [x0, y0, x1, y0, x1, y1, x0, y1, x0, y0]; // closed box+export const HANZI = {+ '一': [[0.5, 6, 11.5, 6]],+ '七': [[0.5, 5.2, 11.5, 5.2], [4.5, 0.5, 4.5, 10.6, 11.5, 10.6, 11.5, 8.6]],+ '个': [[6, 0.4, 0.5, 5.9], [6, 0.4, 11.5, 5.9], [6, 4.4, 6, 11.6]],+ '北': [[4.2, 0.5, 4.2, 11.5], [0.5, 4.5, 4.2, 4.5], [0.5, 10.5, 4.2, 6.8], [7.8, 0.5, 7.8, 10.6, 11.5, 10.6, 11.5, 8.6], [7.8, 6.2, 11, 3]],+ '同': [[1, 11.6, 1, 0.8, 11, 0.8, 11, 11.6, 9.8, 11.6], [3.5, 3.4, 8.5, 3.4], R(3.6, 5.6, 8.4, 9.2)],+ '四': [R(1, 1, 11, 11), [4.6, 1, 4.6, 5.6, 2.8, 7.4], [7.4, 1, 7.4, 6.8, 11, 6.8]],+ '川': [[2.5, 0.5, 2.5, 8, 0.5, 10], [6, 1.2, 6, 9.8], [10.5, 0.5, 10.5, 11.5]],+ '布': [[0.5, 3, 11.5, 3], [6, 0.3, 0.5, 5.8], [3.6, 11, 3.6, 6.2, 10.5, 6.2, 10.5, 9.8, 9.3, 9.8], [7, 4.6, 7, 11.7]],+ '白': [[6.6, 0.2, 5.4, 1.4], R(1.5, 2.5, 10.5, 11.5), [1.5, 7, 10.5, 7]],+ '电': [R(1.5, 2.2, 10.5, 8.6), [1.5, 5.4, 10.5, 5.4], [6, 0.3, 6, 10.6, 11.5, 10.6, 11.5, 9]],+ '重': [[8.8, 0.1, 7.4, 1.5], [1, 2, 11, 2], R(2.5, 3.6, 9.5, 7.4), [2.5, 5.5, 9.5, 5.5], [6, 2, 6, 11.2], [1.8, 9.3, 10.2, 9.3], [0.5, 11.3, 11.5, 11.3]],+ '庆': [[6, 0, 7, 1], [1.6, 1.6, 11.5, 1.6], [2, 1.6, 2, 8.6, 0.5, 10.1], [3.8, 5.2, 11.5, 5.2], [7.6, 2.8, 7.6, 6.4, 2.8, 11.2], [7.6, 6.4, 11.6, 10.4]],+ '江': [[1, 0.8, 2.2, 2], [0.5, 4.2, 1.7, 5.4], [0.5, 11, 3, 8.5], [4.6, 1.5, 11.4, 1.5], [8, 1.5, 8, 10.5], [4, 10.5, 12, 10.5]],+ '湖': [[0.8, 0.8, 1.8, 1.8], [0.4, 4.2, 1.4, 5.2], [0.4, 11, 2.4, 9], [3, 3.4, 7.2, 3.4], [5.1, 0.8, 5.1, 6.4], R(3.6, 6.4, 6.6, 10.4),+ [8.4, 1, 8.4, 9.8, 7.4, 10.8], [8.4, 1, 11.4, 1, 11.4, 11.5, 10.4, 11.5], [8.4, 4.4, 11.4, 4.4], [8.4, 7.4, 11.4, 7.4]],+ '流': [[0.8, 0.8, 1.8, 1.8], [0.4, 4.2, 1.4, 5.2], [0.4, 11, 2.4, 9], [6.8, 0, 7.6, 0.8], [3.4, 1.8, 11.6, 1.8], [6.4, 2.2, 4.6, 4, 10.4, 4], [9, 2.6, 10.4, 4],+ [5, 5.8, 5, 9.2, 3.4, 10.8], [7.6, 5.8, 7.6, 10.6], [10.2, 5.8, 10.2, 10.6, 11.6, 10.6, 11.6, 9.6]],+ '浙': [[0.8, 0.8, 1.8, 1.8], [0.4, 4.2, 1.4, 5.2], [0.4, 11, 2.4, 9], [2.9, 3.6, 6.3, 3.6], [4.6, 0.5, 4.6, 10.6, 3.6, 11.6], [3, 8.8, 6.2, 5.6],+ [11.4, 0.5, 9.4, 0.5, 7.8, 2.1, 7.8, 8.6, 6.4, 10], [7.8, 5, 11.6, 5], [10, 5, 10, 11.6]],+ '站': [[2.8, 0.2, 2.8, 1.6], [0.6, 2.2, 5, 2.2], [1.4, 4, 2.6, 5.2], [4.4, 3.6, 4.4, 5.4, 3.2, 6.6], [0.4, 8.6, 5.2, 8.6],+ [8.6, 0.2, 8.6, 6], [8.6, 3, 11.6, 3], R(6.4, 6, 11.4, 11.4)],+ '拖': [[0.4, 3.6, 4.2, 3.6], [2.4, 0.5, 2.4, 10.6, 1.4, 11.6], [0.6, 9, 4.2, 5.4], [7.6, 0.4, 5.4, 2.6], [6.4, 1.6, 11.4, 1.6],+ [5.6, 5.2, 10.8, 5.2, 10.8, 8, 10, 8.8], [8.2, 3.4, 8.2, 8.8], [5.8, 4, 5.8, 10.8, 11.8, 10.8, 11.8, 9.4]],+ '换': [[0.4, 3.6, 4.2, 3.6], [2.4, 0.5, 2.4, 10.6, 1.4, 11.6], [0.6, 9, 4.2, 5.4], [7.4, 0.2, 5.8, 1.8], [6.8, 0.8, 9.8, 0.8, 8.6, 2],+ [5.6, 6.2, 5.6, 2.8, 11, 2.8, 11, 6.2], [8.1, 3.6, 7.0, 4.7], [8.5, 3.6, 9.6, 4.7], [4.8, 6.4, 11.8, 6.4], [8.3, 5, 8.3, 7.2, 4.4, 11.1], [8.3, 7.2, 12, 10.9]],+ '徽': [[2.4, 0.4, 0.4, 2.4], [2.4, 3, 0.2, 5.2], [1.6, 4, 1.6, 11.6],+ [5.2, 0.4, 5.2, 2.8], [3.4, 1.2, 3.4, 2.8, 7, 2.8, 7, 1.2], [3.2, 4, 7.2, 4], [5.8, 4.6, 4.2, 6.2, 6.2, 6.2], [6, 6.2, 4.2, 8, 7, 8], [6.2, 7.2, 7, 8],+ [5.4, 8, 5.4, 11.6], [4.2, 9.4, 3.2, 10.4], [6.6, 9.4, 7.6, 10.4],+ [9.4, 0.3, 9.4, 1.4, 8, 2.8], [8.6, 2.4, 12, 2.4], [11, 2.4, 11, 5, 7.6, 8.4], [8.6, 5, 11.8, 8.2, 11.8, 11.6]],+ '鹤': [[3.2, -0.2, 3.2, 1], [0.6, 2.4, 0.6, 1.1, 6, 1.1, 6, 2.4], [2.8, 2.6, 1.1, 4.3], [1.7, 3.7, 1.7, 11.6], [3.8, 2.6, 4.6, 3.4], [2.4, 4.6, 6, 4.6],+ [3.7, 4.6, 3.7, 11.2], [2.4, 6.8, 5.6, 6.8], [2.4, 9.0, 5.6, 9.0], [2.2, 11.2, 6.2, 11.2],+ [9.0, 0.0, 8.0, 1.0], [7.6, 1.3, 7.6, 7.2], [7.6, 1.3, 11.2, 1.3, 11.2, 4.6, 10.4, 5.4], [8.9, 2.6, 9.7, 3.4], [7.6, 7.2, 11.8, 7.2, 11.8, 10.6, 10.8, 11.6], [6.6, 9.4, 10.6, 9.4]],+ '滩': [[0.8, 0.8, 1.8, 1.8], [0.4, 4.2, 1.4, 5.2], [0.4, 11, 2.4, 9], [2.6, 2.4, 6, 2.4, 6, 5.2, 2.6, 8.6], [3.4, 5, 6.4, 8],+ [8.4, 0.2, 6.8, 1.8], [7.6, 1.2, 7.6, 11.6], [9.6, 0.2, 10.4, 1], [8.6, 2.6, 12, 2.6], [10, 2.6, 10, 11.2], [8.6, 5.4, 11.6, 5.4], [8.6, 8.2, 11.6, 8.2], [8.4, 11.2, 12, 11.2]],+ '安': [[6, -0.2, 6, 1], [0.8, 3, 0.8, 1.4, 11.2, 1.4, 11.2, 2.6, 10.6, 3.2], [5.6, 3.4, 3.6, 5.4, 3.6, 6, 8.6, 11], [8.6, 4.2, 8.6, 6.4, 3.4, 11.6], [0.6, 6.6, 11.4, 6.6]],+ '苏': [[0.6, 2.4, 11.4, 2.4], [3.6, 0.3, 3.6, 3.8], [8.4, 0.3, 8.4, 3.8], [2.8, 5.8, 9.6, 5.8, 9.6, 11.6, 8.4, 11.6], [6, 4.2, 6, 7.8, 2.4, 11.4], [2.2, 7.4, 1, 8.6], [10.6, 7.6, 11.6, 8.6]],+ '虞': [[5.6, -0.2, 5.6, 2.4], [5.6, 1, 9.6, 1], [1.8, 2.6, 11.2, 2.6, 11.2, 3.4], [1.8, 2.6, 1.8, 9.6, 0.4, 11], [3.4, 4.2, 9.4, 4.2], [5.4, 3.2, 5.4, 5.6, 10.4, 5.6],+ R(4.4, 6.6, 8.6, 8.4), [3.2, 9.4, 10.4, 9.4], [6.6, 8.4, 6.6, 9.6, 4.6, 11.6], [6.8, 9.8, 8.6, 11.6]],+ '城': [[0.4, 4, 3.8, 4], [2, 1, 2, 9.4], [0.4, 10.4, 3.8, 7], [5.2, 3, 12, 3], [5.2, 3, 5.2, 9.4, 4, 10.6], [5.2, 6, 7.6, 6, 7.6, 8.6, 7, 9.2],+ [8.6, 0.4, 8.6, 4.6, 12, 8, 12, 10.8], [10.4, 0.4, 11.2, 1.2], [11.4, 5.2, 8, 8.6]],+ '毫': [[6, -0.2, 6, 0.8], [0.6, 1.2, 11.4, 1.2], R(3.6, 2.2, 8.4, 3.8), [1, 5.6, 1, 4.6, 11, 4.6, 11, 5.6], [9.4, 5.4, 8.4, 6.4],+ [2.6, 7, 9.6, 7], [2, 9, 10, 9], [6, 6, 6, 11.2, 11.6, 11.2, 11.6, 10]],+ '秒': [[4, 0.3, 2.8, 1.5], [0.4, 3.2, 5, 3.2], [2.8, 1.2, 2.8, 11.6], [2.8, 4.2, 0.4, 6.6], [3.2, 5, 4.6, 6.4],+ [8.6, 0.2, 8.6, 6.6], [6.8, 2, 6.8, 3.4, 5.8, 4.4], [10.4, 2, 11.6, 3.2], [11.6, 6, 6.2, 11.4]],+ '路': [R(0.8, 0.8, 4.4, 4), [2.6, 4, 2.6, 10], [2.6, 6.8, 4.6, 6.8], [0.8, 6, 0.8, 10.8, 2.6, 10.8, 4.8, 8.6],+ [8, 0.2, 5.6, 2.6], [7.6, 1.2, 11, 1.2, 6, 6.2], [8.2, 2.8, 11.8, 6.4], R(6.6, 7.2, 11, 11.4)],+ '交': [[6, 0, 6, 1.4], [0.8, 2.2, 11.2, 2.2], [4, 3.4, 2.2, 5.2], [8, 3.4, 9.8, 5.2], [3, 5.6, 9, 11.6], [9.2, 5.6, 3.2, 11.6]],+ '直': [[1.6, 1.8, 10.4, 1.8], [6, 0, 6, 3.4], R(3.2, 3.4, 8.8, 10.2), [3.2, 5.6, 8.8, 5.6], [3.2, 7.9, 8.8, 7.9], [1.6, 3.4, 1.6, 11.6, 11.2, 11.6]],+ '损': [[0.4, 3.6, 4.2, 3.6], [2.4, 0.5, 2.4, 10.6, 1.4, 11.6], [0.6, 9, 4.2, 5.4], R(6, 0.6, 10.6, 3.4), [5.4, 9.4, 5.4, 4.6, 11.2, 4.6, 11.2, 9.4], [8.3, 5.8, 8.3, 9, 5.8, 11.5], [9, 9.6, 11, 11.6]],+ '耗': [[0.6, 1.6, 4.6, 1.6], [0.4, 3.8, 4.8, 3.8], [0.2, 6.2, 5, 6.2], [2.6, 0.2, 2.6, 11.6], [2.6, 7.2, 0.4, 9.4], [2.8, 7.8, 4.4, 9.4],+ [10.6, 0.4, 9.4, 1.6], [6, 2.6, 11, 2.6], [5.6, 5.2, 11.4, 5.2], [8.4, 1.6, 8.4, 10.6, 11.6, 10.6, 11.6, 9]],+ '公': [[4.2, 0.6, 0.6, 4.2], [7.6, 0.6, 11.4, 4.4], [5.8, 4.4, 2.2, 8, 2.2, 10.4, 9.8, 10.4], [8.2, 7.6, 10.6, 10]],+ '里': [R(1.6, 0.8, 10.4, 6.8), [1.6, 3.8, 10.4, 3.8], [6, 0.8, 6, 11.2], [2.4, 8.8, 9.6, 8.8], [0.6, 11.2, 11.4, 11.2]],+ '降': [[1, 11.6, 1, 0.6, 3.8, 0.6, 3.8, 1.6, 2.4, 3], [2.4, 3, 3.8, 4.4, 3.8, 6.4, 2.6, 7.6], [7.2, 0.2, 5.6, 1.8], [6.6, 1, 10.6, 1, 6.2, 5.4], [8, 3, 11, 6],+ [6, 6.8, 10.4, 6.8], [6, 6.8, 6, 9], [5.2, 9, 11.6, 9], [8.4, 6.8, 8.4, 11.8]],+ '压': [[1.6, 1.2, 11.4, 1.2], [1.6, 1.2, 1.6, 9.2, 0.4, 10.4], [3.6, 5.6, 10.4, 5.6], [7, 2.8, 7, 10.8], [3, 10.8, 11.6, 10.8], [9, 7.4, 10, 8.4]],+ '充': [[6, 0, 6, 1.2], [1, 1.8, 11, 1.8], [5.6, 2.6, 3.6, 4.6, 9.4, 4.6], [8.2, 3.2, 9.6, 4.6], [4.6, 6.2, 4.6, 8.8, 1.8, 11.6], [7.4, 6.2, 7.4, 10.6, 11.6, 10.6, 11.6, 9.2]],+ '器': [R(1, 0.6, 4.8, 3.6), R(7.2, 0.6, 11, 3.6), R(1, 8.4, 4.8, 11.4), R(7.2, 8.4, 11, 11.4), [0.4, 6, 11.6, 6], [6.2, 4, 6.2, 6, 4.2, 8], [6.6, 6.4, 8.2, 8], [8.2, 4, 9, 4.8]],+ '整': [[0.8, 1.6, 6, 1.6], [3.4, 0.2, 3.4, 6.2], R(1.4, 2.6, 5.4, 4.4), [3, 4.6, 1, 6.6], [3.8, 4.6, 5.6, 6.4],+ [8.6, 0.2, 7.4, 1.4], [7.8, 1.2, 11.6, 1.2], [10.6, 1.2, 10.6, 2.6, 7.4, 5.8], [8.6, 3.2, 11.4, 6],+ [1.6, 7, 10.4, 7], [6, 7, 6, 11.4], [6, 9.2, 9.4, 9.2], [3, 8.6, 3, 11.4], [0.4, 11.4, 11.6, 11.4]],+ '桥': [[0.4, 3.6, 4.6, 3.6], [2.4, 0.4, 2.4, 11.6], [2.4, 4.4, 0.4, 6.4], [2.6, 5, 4, 6.4],+ [10.6, 0.2, 9.4, 1.4], [5.6, 2.2, 11.4, 2.2], [8.6, 2.2, 8.6, 3.2, 5.6, 6.2], [8.8, 3.4, 11.4, 6], [7.2, 7.6, 7.2, 9.6, 5.4, 11.4], [10, 7.4, 10, 11.8]],+ '原': [[1.4, 1, 11.6, 1], [1.4, 1, 1.4, 9.4, 0.2, 10.6], [6.8, 1.6, 6, 2.4], R(3.6, 3, 10, 7.2), [3.6, 5.1, 10, 5.1], [6.8, 7.2, 6.8, 10.8, 5.8, 11.8], [4.6, 8.6, 3, 10.2], [9, 8.6, 10.6, 10.2]],+ '理': [[0.6, 1.4, 4.4, 1.4], [0.8, 5.4, 4.2, 5.4], [2.5, 1.4, 2.5, 10], [0.4, 10, 2.5, 10, 4.4, 8.1], R(5.6, 0.8, 11.2, 6.4), [5.6, 3.6, 11.2, 3.6], [8.4, 0.8, 8.4, 11], [6.2, 8.6, 10.6, 8.6], [5.2, 11, 11.8, 11]],+ '功': [[0.6, 2, 5, 2], [2.8, 2, 2.8, 9.8], [0.4, 9.8, 2.8, 9.8, 5, 7.6], [6, 4, 11.4, 4, 11.4, 10.6, 10.4, 11.6], [8.6, 0.4, 8.6, 6.6, 5.4, 9.8]],+ '率': [[6, 0, 6, 1.2], [0.8, 1.8, 11.2, 1.8], [6.4, 2.6, 4.8, 4.2, 7, 4.2], [6.8, 4.2, 4.6, 6.4, 8.4, 6.4], [7.6, 5.4, 8.4, 6.2], [2, 3, 3, 4], [1.4, 6.4, 2.8, 5], [10, 3, 9, 4], [9.4, 5, 10.8, 6.4], [0.6, 8.2, 11.4, 8.2], [6, 6.4, 6, 11.8]],+ '差': [[3.6, 0.2, 4.4, 1], [8.4, 0.2, 7.6, 1], [1.4, 1.8, 10.6, 1.8], [1.8, 3.8, 10.2, 3.8], [0.6, 5.8, 11.4, 5.8], [6, 1.8, 6, 5.8, 1, 10.8], [4.6, 7.8, 10.4, 7.8], [7.5, 7.8, 7.5, 11], [4, 11, 11.2, 11]],+ '亿': [[3.2, 0.4, 0.4, 3.2], [1.8, 1.8, 1.8, 11.6], [5, 1.6, 10.6, 1.6, 5.2, 7], [5.2, 7, 5.2, 10.6, 11.6, 10.6, 11.6, 8.8]],+ '倍': [[3.2, 0.4, 0.4, 3.2], [1.8, 1.8, 1.8, 11.6], [7.4, 0, 7.4, 1.2], [4.2, 1.6, 11.6, 1.6], [5.6, 2.6, 6.8, 3.8], [10.2, 2.6, 9, 3.8], [3.8, 4.8, 11.8, 4.8], R(5, 6.6, 10.6, 11.2)],+};diff --git a/styles/circuit-board/demo/src/house.js b/styles/circuit-board/demo/src/house.jsnew file mode 100644index 0000000..beb2dac--- /dev/null+++ b/styles/circuit-board/demo/src/house.js@@ -0,0 +1,74 @@+// The street module (a child board of the city), 1 unit = 10 cm. One residential block of 18 floors drawn as a pad+// array (no windows, no people), the pole transformer T4 on the street, a wall socket, and the charger beside it.+import { measure } from './geo.js';+import { xformer, box, chamferBox } from './parts.js';+import { stepLabel } from './world.js';+import { mulberry } from '/core/lib.js';++export const BOARD = { x0: 0, y0: 0, x1: 900, y1: 900, r: 4, inset: 1 };+export const CLR = 1.6, VIA_R = 1.4, FENCE_R = 1;+export const STREETS = [{ pts: [[-10, 812], [910, 812]], w: 40 }, { pts: [[-10, 784], [910, 784]], w: 3 }];+export const T4 = xformer([110, 752], 30, [8, 2], 0.8);+// the building: 18 floors x 6 homes+export const FLOORS = 18, HOMES = 6, BX = 300, BY = 120, FH = 30, HW = 48;+export const homePos = (f, u) => [BX + 10 + u * HW + 21, BY + (FLOORS - 1 - f) * FH + 15]; // f = 0 is the ground floor+export const TPADS = [];+for (let f = 0; f < FLOORS; f++) for (let u = 0; u < HOMES; u++) { const [x, y] = homePos(f, u); TPADS.push({ x, y, w: 40, h: 17, lit: true, home: true, f, u, r: 2 }); }+const RISER = 282;+const tr = (id, pts, w, net) => ({ id, pts, w, net });+const feed = [tr('in', [[0, 752], T4.inP], 1.3, 'ac'), tr('out', [T4.outP, [RISER, 752], [RISER, BY + 8]], 0.65, 'ac')];+const floors = [];+for (let f = 0; f < FLOORS; f++) { const y = homePos(f, 0)[1]; floors.push(tr('fl' + f, [[RISER, y], [homePos(f, 0)[0] - 20, y]], 0.5, 'ac')); }+// the socket: a wall plate with two oval holes; floor 3's last home feeds it+export const SOCKET = { c: [740, 560], s: 74, holeL: [722, 556], holeN: [758, 556] };+const sF = 3, sy = homePos(sF, HOMES - 1)[1];+const toSocket = tr('sock', [[homePos(sF, HOMES - 1)[0] + 20, sy], [612, sy], [612, 507], [SOCKET.holeL[0], 507], [SOCKET.holeL[0], SOCKET.holeL[1] - 9]], 0.6, 'ac');+// the wall: neutral and earth run beside the live wire to a switch, this socket and the next one+const wall = [tr('N', [[618, 513], [SOCKET.holeN[0], 513], [SOCKET.holeN[0], SOCKET.holeN[1] - 9]], 0.6, 'idle'), tr('PE', [[624, 519], [SOCKET.c[0], 519], [SOCKET.c[0], 527]], 0.6, 'idle'),+ tr('L2', [[SOCKET.holeL[0], 507], [912 - 100, 507], [812, 547]], 0.6, 'idle'), tr('N2', [[SOCKET.holeN[0], 513], [848, 513], [848, 547]], 0.6, 'idle'),+ tr('S1', [[612, 507], [612, 530], [640, 530], [640, 540]], 0.6, 'idle')];+export const TRACES = [...feed, ...floors, toSocket, ...wall].map(t => ({ ...t, m: measure(t.pts) }));+export const byId = id => TRACES.find(t => t.id === id);+// the neighbours along the street (pad arrays, unlit mostly)+const rnd = mulberry(5);+for (const [x0, y0, nx, ny] of [[20, 380, 4, 9], [660, 660, 4, 3], [180, 640, 2, 2], [-6, 692, 5, 1], [150, 850, 6, 1], [-20, 850, 3, 1]]) {+ for (let a = 0; a < nx; a++) for (let b = 0; b < ny; b++) TPADS.push({ x: x0 + 21 + a * 48, y: y0 + 15 + b * 30, w: 40, h: 17, lit: rnd() < 0.7, r: 2 });+}+export const CHARGER_AT = [740, 616], CHARGER_S = 0.2;+const SW = [650, 566], S2 = [830, 560];+import { } from './geo.js'; // 1 mm = 0.2 units (drawn large)+const plate = SOCKET.s / 2;+export const PADS = [...T4.pads, { x: SOCKET.holeL[0], y: SOCKET.holeL[1] - 9, r: 1.6, shape: 'round', hole: 0, id: 'sL' }];+export const SCREWS = [[SOCKET.c[0], SOCKET.c[1] - 27], [SOCKET.c[0], SOCKET.c[1] + 27]];+export const VIAS = [...SCREWS, [SW[0], SW[1] - 22], [SW[0], SW[1] + 22], [S2[0], S2[1] - 27], [S2[0], S2[1] + 27]].map(p => [p[0], p[1], 3.2, 1.6]);+export const SILK = [+ ...T4.silk,+ { pts: box(BX, BY - 6, BX + 10 + HOMES * HW + 6, BY + FLOORS * FH + 4), w: 1.2 }, // building outline+ { pts: chamferBox(SOCKET.c[0] - plate, SOCKET.c[1] - plate, SOCKET.c[0] + plate, SOCKET.c[1] + plate, 10), w: 1.6 },+ { pts: chamferBox(SOCKET.c[0] - plate + 6, SOCKET.c[1] - plate + 6, SOCKET.c[0] + plate - 6, SOCKET.c[1] + plate - 6, 7), w: 0.7 },+ // the switch beside it, the next socket, and the wall boxes behind all three (dashed)+ { pts: chamferBox(SW[0] - 28, SW[1] - 28, SW[0] + 28, SW[1] + 28, 8), w: 1.4 }, { pts: box(SW[0] - 9, SW[1] - 16, SW[0] + 9, SW[1] + 16), w: 1 }, { pts: [[SW[0] - 9, SW[1]], [SW[0] + 9, SW[1]]], w: 0.8 },+ { pts: chamferBox(S2[0] - plate, S2[1] - plate, S2[0] + plate, S2[1] + plate, 10), w: 1.6 },+ ...[[SW, 32], [SOCKET.c, plate + 4], [S2, plate + 4]].map(([c, r]) => ({ pts: box(c[0] - r, c[1] - r, c[0] + r, c[1] + r), w: 0.5, dash: [3, 2.4] })),+ { pts: [[600, 507], [606, 507]], w: 0.6 },+ { pts: box(CHARGER_AT[0] - 16 * CHARGER_S - 0.6, CHARGER_AT[1] - 6 * CHARGER_S - 0.6, CHARGER_AT[0] + 53 * CHARGER_S + 0.6, CHARGER_AT[1] + 33 * CHARGER_S + 0.6), w: 0.06 },+ // noon: a sun and a clock (hands both at twelve), drawn, no figures+ { circle: [690, 160, 16], w: 1.4 }, ...[...Array(8).keys()].map(k => { const a = k * Math.PI / 4; return { pts: [[690 + Math.cos(a) * 22, 160 + Math.sin(a) * 22], [690 + Math.cos(a) * 30, 160 + Math.sin(a) * 30]], w: 1.4 }; }),+ { circle: [770, 160, 26], w: 1.4 }, { pts: [[770, 160], [770, 140]], w: 2 }, { pts: [[770, 160], [770, 146]], w: 3 },+ ...[...Array(12).keys()].map(k => { const a = k * Math.PI / 6; return { pts: [[770 + Math.cos(a) * 21, 160 + Math.sin(a) * 21], [770 + Math.cos(a) * 24, 160 + Math.sin(a) * 24]], w: 1 }; }),+];+export const KEEP = [...T4.keep, { rect: [BX - 2, BY - 8, BX + 10 + HOMES * HW + 8, BY + FLOORS * FH + 6] },+ { rect: [SOCKET.c[0] - plate - 2, SOCKET.c[1] - plate - 2, SOCKET.c[0] + plate + 2, SOCKET.c[1] + plate + 2] },+ { rect: [SW[0] - 30, SW[1] - 30, SW[0] + 30, SW[1] + 30] }, { rect: [S2[0] - plate - 2, S2[1] - plate - 2, S2[0] + plate + 2, S2[1] + plate + 2] },+ { rect: [CHARGER_AT[0] - 16 * CHARGER_S - 1, CHARGER_AT[1] - 6 * CHARGER_S - 1, CHARGER_AT[0] + 53 * CHARGER_S + 1, CHARGER_AT[1] + 33 * CHARGER_S + 1] },+];+export const HOLES_OVAL = [SOCKET.holeL, SOCKET.holeN, [S2[0] - 18, S2[1] - 4], [S2[0] + 18, S2[1] - 4]];+export const DESIG = [+ { text: 'X1', x: SOCKET.c[0] - plate + 4, y: SOCKET.c[1] + plate + 6.5, cap: 4, align: 'left' }, { text: 'X2', x: S2[0] - plate + 4, y: S2[1] + plate + 6.5, cap: 4, align: 'left' },+ { text: 'S1', x: SW[0] - 26, y: SW[1] + 34.5, cap: 4, align: 'left' }, { text: '220 V ~ 50 Hz', x: SOCKET.c[0] + plate - 4, y: SOCKET.c[1] + plate + 6.5, cap: 3.6, align: 'right' },+ { text: 'L', x: 597, y: 505, cap: 3, align: 'right' }, { text: 'N', x: 615, y: 511, cap: 3, align: 'right' }, { text: 'PE', x: 621, y: 517, cap: 3, align: 'right' },+ { text: 'L', x: SOCKET.holeL[0] - 4.5, y: SOCKET.holeL[1] + 17, cap: 4, align: 'left' }, { text: 'N', x: SOCKET.holeN[0] - 4.5, y: SOCKET.holeN[1] + 17, cap: 4, align: 'left' },+ ...[...Array(FLOORS).keys()].map(f => ({ text: `${f + 1}F`, x: BX - 6, y: homePos(f, 0)[1] - 2.5, cap: 5, align: 'right' })),+];+export const LABELS = stepLabel(T4).map(l => ({ ...l, id: l.id + '4' }));+export const CHILD = { name: 'charger', at: CHARGER_AT, s: CHARGER_S };diff --git a/styles/circuit-board/demo/src/levels.js b/styles/circuit-board/demo/src/levels.jsnew file mode 100644index 0000000..1009df3--- /dev/null+++ b/styles/circuit-board/demo/src/levels.js@@ -0,0 +1,46 @@+// Nested boards: corridor (km) ⊃ city (10 m) ⊃ street (10 cm) ⊃ charger (mm). Each child board sits in its parent at+// `at` (parent units) with `s` parent units per child unit. A camera is always held in one level's own units, so+// the canvas never sees huge numbers; the stack renderer starts from the outermost level that still has to be+// drawn and composites every visible child into its footprint.+import { Board, camMatrix, toScreen } from './render.js';++export function makeLevels(defs, W, H) {+ const L = {};+ for (const d of defs) L[d.name] = { ...d, cv: new OffscreenCanvas(W, H), kids: [] };+ for (const d of defs) { const l = L[d.name]; l.ctx = l.cv.getContext('2d'); l.board = new Board(l.cv, d.world, { unit: d.unit }); if (d.parent) L[d.parent].kids.push(l); }+ return L;+}+// camera conversions between a level and its parent+export const toChild = (cam, k) => ({ x: (cam.x - k.at[0]) / k.s, y: (cam.y - k.at[1]) / k.s, z: cam.z * k.s, r: cam.r || 0 });+export const toParent = (cam, k) => ({ x: cam.x * k.s + k.at[0], y: cam.y * k.s + k.at[1], z: cam.z / k.s, r: cam.r || 0 });+function covers(l, cam, W, H) {+ const M = camMatrix(cam), det = M[0] * M[3] - M[1] * M[2], B = l.world.BOARD;+ const inv = p => { const x = p[0] - M[4], y = p[1] - M[5]; return [(M[3] * x - M[2] * y) / det, (-M[1] * x + M[0] * y) / det]; };+ return [[0, 0], [W, 0], [0, H], [W, H]].every(p => { const q = inv(p); return q[0] > B.x0 && q[0] < B.x1 && q[1] > B.y0 && q[1] < B.y1; });+}+// the outermost level to draw for a camera held in level `name`+export function baseOf(L, name, cam, W, H) {+ let l = L[name], c = cam;+ while (l.parent && !covers(l, c, W, H)) { c = toParent(c, l); l = L[l.parent]; }+ return { l, cam: c };+}+// draw level l (and its visible children) into l.cv; returns the list of [level, cam, clipRect] drawn (for texts)+export function drawLevel(L, l, cam, sceneFor, W, H, out = []) {+ l.board.frame(cam, sceneFor(l.name));+ out.push([l, cam, null]);+ const M = camMatrix(cam);+ for (const k of l.kids) {+ const B = k.world.BOARD, p0 = toScreen(M, [k.at[0] + B.x0 * k.s, k.at[1] + B.y0 * k.s]), p1 = toScreen(M, [k.at[0] + B.x1 * k.s, k.at[1] + B.y1 * k.s]);+ const x0 = Math.min(p0[0], p1[0]), x1 = Math.max(p0[0], p1[0]), y0 = Math.min(p0[1], p1[1]), y1 = Math.max(p0[1], p1[1]);+ if (x1 - x0 < 3 || x1 < 0 || y1 < 0 || x0 > W || y0 > H) continue;+ const kc = toChild(cam, k), n = out.length;+ drawLevel(L, k, kc, sceneFor, W, H, out);+ for (let i = n; i < out.length; i++) out[i][2] = out[i][2] || [x0, y0, x1, y1];+ const g = l.ctx; g.save(); g.setTransform(1, 0, 0, 1, 0, 0);+ // the child footprint follows the camera's rotation: clip to its rotated outline+ const c = [[B.x0, B.y0], [B.x1, B.y0], [B.x1, B.y1], [B.x0, B.y1]].map(q => toScreen(M, [k.at[0] + q[0] * k.s, k.at[1] + q[1] * k.s]));+ g.beginPath(); g.moveTo(...c[0]); for (const q of c.slice(1)) g.lineTo(...q); g.closePath(); g.clip();+ g.drawImage(k.cv, 0, 0); g.restore();+ }+ return out;+}diff --git a/styles/circuit-board/demo/src/loss.js b/styles/circuit-board/demo/src/loss.jsnew file mode 100644index 0000000..a24ddb7--- /dev/null+++ b/styles/circuit-board/demo/src/loss.js@@ -0,0 +1,32 @@+// "If you sent it as it is": a long straight board with one AC trace whose light fades as it goes.+// A stand-alone board (not nested), units are arbitrary (the bus runs 1,200 units).+import { measure } from './geo.js';+import { box, chip } from './parts.js';+import { mulberry } from '/core/lib.js';++export const BOARD = { x0: -200, y0: 0, x1: 1500, y1: 520, r: 10, inset: 3 };+export const CLR = 3, VIA_R = 2.6, FENCE_R = 2;+const Y = 260;+const tr = (id, pts, w, net) => ({ id, pts, w, net });+export const TRACES = [+ tr('ac', [[-210, Y], [1510, Y]], 12, 'ac'),+ ...[-2, -1, 1, 2].map(k => tr('idle' + k, [[-210, Y + k * 30 + Math.sign(k) * 10], [1510, Y + k * 30 + Math.sign(k) * 10]], 3, 'idle')),+].map(t => ({ ...t, m: measure(t.pts) }));+export const byId = id => TRACES.find(t => t.id === id);+export const PADS = [], SILK = [], KEEP = [], DESIG = [], VIAS = [];+// distance ruler on the silkscreen above the bus, a test pad every 200 units+for (let x = -200; x <= 1500; x += 50) SILK.push({ pts: [[x, Y - 92], [x, Y - 92 - (x % 200 === 0 ? 14 : 7)]], w: 1.4 });+SILK.push({ pts: [[-200, Y - 92], [1500, Y - 92]], w: 1.2 });+for (let x = 0; x <= 1400; x += 200) { PADS.push({ x, y: Y - 40, r: 6, shape: 'round', hole: 2.4, id: 'tp' + x }); SILK.push({ circle: [x, Y - 40, 10], w: 1.2 }); TRACES.push({ id: 'st' + x, pts: [[x, Y - 4], [x, Y - 34]], w: 2, net: 'idle', m: measure([[x, Y - 4], [x, Y - 34]]) }); }+// decoupling parts along the idle buses (texture), seeded+const rnd = mulberry(41);+for (let x = -150; x < 1450; x += 70 + Math.floor(rnd() * 60)) for (const yy of [Y + 128, Y - 138]) {+ if (yy < Y && x > 640 && x < 890) continue;+ const c = chip([x, yy], 10, 4, 6, { sw: 0.9 }); PADS.push(...c.pads); SILK.push(...c.silk); KEEP.push(...c.keep);+}+export const LABELS = [+ { id: 'loss', gid: 'loss', text: '损耗', x: 765, y: Y - 196, cap: 36, sw: 3.6, align: 'center' },+ { id: 'lossE', gid: 'lossE', text: 'LOSS', x: 765, y: Y - 140, cap: 16, sw: 2.6, align: 'center' },+];++export const CHILD = null;diff --git a/styles/circuit-board/demo/src/main.js b/styles/circuit-board/demo/src/main.jsnew file mode 100644index 0000000..5b5c3c5--- /dev/null+++ b/styles/circuit-board/demo/src/main.js@@ -0,0 +1,359 @@+// Seven Milliseconds — timeline: cameras, scene state per board, subtitles, sound events. render(t) depends on t only.+// Four nested boards (levels.js): corridor (km) ⊃ city (10 m) ⊃ street (10 cm) ⊃ charger (mm); plus a stand-alone+// "loss" board for the one shot that shows what would happen to AC sent that far.+// Shots follow the voice (voice/, edge-tts +20%); VO[] holds each line's start time.+import { Board, setSize, camFor, camMatrix, toScreen } from './render.js';+import * as CW from './world.js';+import * as CT from './city.js';+import * as HS from './house.js';+import * as CH from './charger.js';+import * as LS from './loss.js';+import { makeLevels, toChild, toParent, baseOf, drawLevel } from './levels.js';+import { makePost } from './post.js';+import { at } from './geo.js';+import { clamp, lerp, seg, ss, eio, eo, ei, monotone } from '/core/lib.js';++const W = 1920, H = 1080; // always drawn at 1080p; the page scales it to any viewport+setSize(W, H);+const cv = document.getElementById('c'); cv.width = W; cv.height = H;+const ctx = cv.getContext('2d');+const LV = makeLevels([+ { name: 'corridor', world: CW, unit: 1 },+ { name: 'city', world: CT, unit: 1, parent: 'corridor', at: CW.CHILD.at, s: CW.CHILD.s },+ { name: 'house', world: HS, unit: 1, parent: 'city', at: CT.CHILD.at, s: CT.CHILD.s },+ { name: 'charger', world: CH, unit: 0.05, parent: 'house', at: HS.CHILD.at, s: HS.CHILD.s },+ { name: 'loss', world: LS, unit: 2 },+], W, H);+const bcv = new OffscreenCanvas(W, H), bubbleBoard = new Board(bcv, CW, { unit: 1, noDesig: true });+const post = makePost(W, H);+const subFont = new FontFace('SubSC', 'url(fonts/NotoSansSC-Medium-sub.ttf)');+document.fonts.add(await subFont.load());+const [EN, VOTXT, DURS] = await Promise.all([fetch('data/subs_en.json').then(r => r.json()), fetch('voice/lines.json').then(r => r.json()), fetch('voice/dur.json').then(r => r.json())]);++export const DUR = 60;+const LN = Math.log, logLerp = (a, b, e) => Math.exp(lerp(LN(a), LN(b), e));+const BPM = 100, B16 = 60 / BPM / 4;+// the voice: start of each line (gaps of 0.3 s), its subtitle in Chinese (the line itself) and English+const VO = [0.40, 5.58, 10.22, 14.55, 19.24, 23.53, 27.15, 34.20, 42.24, 48.39, 53.05];+const SUBS = VO.map((t0, i) => { const id = VOTXT[i].id; return { id, t0: t0 - 0.05, t1: t0 + DURS[id] + 0.12, cn: VOTXT[i].text, en: EN[i][1] }; });++// ======================= the corridor board =======================+const ORDER = []; for (let k = 0; k < 8; k++) ORDER.push(`G${1 + k}`, `G${9 + k}`);+const tGen = id => ORDER.indexOf(id) * B16;+const PEN_T = 0.42;+const genOf = id => CW.GENS.find(g => g.id === id), penOf = g => CW.PENS.find(p => p.s === g.s && p.k === g.k);+const G1 = genOf('G1'), D = CW.D, BT = CW.BUTUO.c, YC = CW.YUCHENG.c;+const T = id => CW.byId(id);+const ACR = T('acR'), ACB2 = T('acB2'), ACL = T('acL'), BARR = T('barR'), BARL = T('barL'), DCP = T('dcp'), DCN = T('dcn'), L = DCP.m.len;+const fR = monotone([[1.2, 0], [3.6, 0.35 * ACR.m.len], [4.9, ACR.m.len]]);+const fB2 = t => ACB2.m.len * clamp((t - 15.0) / 0.4);+// AC phase: the mains rhythm, slowed right down while the voice explains it (5.4–10.1 s), so the swing reads+const acPhase = t => 2 * Math.PI * (t < 5.4 ? 2.2 * t : t < 10.1 ? 2.2 * 5.4 + 0.55 * (t - 5.4) : 2.2 * 5.4 + 0.55 * 4.7 + 2.2 * (t - 10.1));+const T_IN = 16.3; // Butuo starts conducting+const headS = monotone([[16.5, 0], [17.6, 55], [18.8, 130], [19.1, 175], [20.3, 0.42 * L], [21.8, 0.7 * L], [23.0, L]]);+const headT = s => { let a = 16.5, b = 23.0; for (let i = 0; i < 40; i++) { const m = (a + b) / 2; if (headS(m) < s) a = m; else b = m; } return a; };+const T_ARR = 23.0, T_AC = 27.4; // DC lands; AC leaves Yucheng++// cameras+const camDam = t => {+ const zA = 62, zB = 6.1, cA = [G1.x + 2, G1.y + 2], cB = [D[0], D[1] - 6 * CW.DS];+ const e = eio(seg(t, 0.35, 2.05)), k = ss(seg(t, 0.35, 1.9));+ return { x: lerp(cA[0], cB[0], k), y: lerp(cA[1], cB[1], k), z: logLerp(zA, zB, e) * (1 + 0.012 * Math.max(0, t - 2.05)), r: 0 };+};+const BUSPT = [D[0] + 96 * CW.DS, D[1] + 4 * CW.DS]; // a point on the right-bank bus+const camBus = t => { // 4.7–10.1: in to the bus, hold+ const a = camDam(4.7), b = camFor(BUSPT, [1400, 560], 20), e = eio(seg(t, 4.7, 5.9));+ const c = { x: lerp(a.x, b.x, e), y: lerp(a.y, b.y, e) - 0.2 * Math.max(0, t - 5.9), z: logLerp(a.z, 22, e) };+ return { ...c, r: 0 };+};+const camLoss = t => { const e = ss(seg(t, 10.1, 14.4)); return { x: lerp(200, 760, e), y: 262, z: lerp(2.45, 2.3, e), r: 0 }; };+const ZB0 = 20, ZB1 = 27;+const camButuo = t => camFor(BT, [700, 470], logLerp(ZB0, ZB1, ss(seg(t, 14.4, 18.6))));+const ZT = 2.0, ZF = 1.12, CF = [(BT[0] + YC[0]) / 2 - 36, (BT[1] + YC[1]) / 2 + 40];+const camTrack = t => camFor(at(DCP.m, headS(Math.min(t, T_ARR))), [1340, 540], ZT);+const camWhip = t => { const k = ei(seg(t, 18.75, 19.1)), a = camButuo(18.75), b = camTrack(19.1); return { x: lerp(a.x, b.x, k), y: lerp(a.y, b.y, k), z: logLerp(a.z, b.z, k), r: 0 }; };+const YCAM = camFor([YC[0] + 10, YC[1] + 5], [960, 500], 26);+const camCorr = t => {+ if (t < T_ARR) { const tr = camTrack(t), e = eio(seg(t, 19.7, 21.4)); return { x: lerp(tr.x, CF[0], e), y: lerp(tr.y, CF[1], e), z: logLerp(ZT, ZF, e), r: 0 }; }+ const e = ei(seg(t, T_ARR, 23.5)), z = logLerp(ZF, 26, e);+ const p = toScreen(camMatrix({ x: CF[0], y: CF[1], z: ZF, r: 0 }), [YCAM.x, YCAM.y]);+ return camFor([YCAM.x, YCAM.y], [lerp(p[0], 960, ss(seg(t, T_ARR, 23.4))), lerp(p[1], 540, ss(seg(t, T_ARR, 23.4)))], z);+};+const camYuch = t => ({ ...YCAM, z: 26 * (1 + 0.008 * (t - 23.5)) });++// the step-down cuts: the same symbol at the same screen size (300 px), four scales+const CUTS = [+ { t0: 29.6, level: 'corridor', c: CW.T1.c, s: CW.T1.s, push: 0.05 },+ { t0: 30.3, level: 'city', c: CT.T2.c, s: CT.T2.s, push: 0.05 },+ { t0: 31.0, level: 'city', c: CT.T3.c, s: CT.T3.s, push: 0.05 },+ { t0: 31.7, level: 'house', c: HS.T4.c, s: HS.T4.s, push: 0.22 },+];+const camCut = (k, t) => { const c = CUTS[k], z = 300 / c.s * (1 + c.push * eio(seg(t, c.t0, c.t0 + 0.7))); return { x: c.c[0], y: c.c[1], z, r: 0 }; };++// the street: the block flashes by, the socket wall, the plunge into the live hole+const SK = HS.SOCKET;+const SKC = { x: SK.c[0] + 6, y: SK.c[1] + 10, z: 8.6 };+const camStreet = t => {+ if (t < 34.0) {+ const a = { x: 450, y: 380, z: 2.0 }, e = eio(seg(t, 32.45, 32.95));+ return { x: lerp(a.x, SKC.x, e), y: lerp(a.y, SKC.y, e), z: logLerp(a.z, SKC.z, e) * (1 + 0.06 * ss(seg(t, 32.95, 34.0))), r: 0 };+ }+ const e = ei(seg(t, 34.0, 34.6)), z0 = SKC.z * 1.06, z = logLerp(z0, 2600, e);+ const p = toScreen(camMatrix({ x: SKC.x, y: SKC.y, z: z0, r: 0 }), SK.holeL);+ return camFor(SK.holeL, [lerp(p[0], 960, ss(seg(t, 34.0, 34.3))), lerp(p[1], 540, ss(seg(t, 34.0, 34.3)))], z);+};++// the charger: out of the L pad's hole, the whole small board, then in to the bridge+const ZC = 36, DBPOS = [640, 410];+const camVerdictBase = camFor(CH.DB1.c, DBPOS, ZC);+const WHOLE = { x: 18.5, y: 14, z: 20 };+const camCharger = t => {+ if (t < 35.35) { const e = eo(seg(t, 34.6, 35.35)), p = [lerp(CH.LPAD[0], WHOLE.x, ss(seg(t, 34.75, 35.35))), lerp(CH.LPAD[1], WHOLE.y, ss(seg(t, 34.75, 35.35)))]; return { x: p[0], y: p[1], z: logLerp(2400, WHOLE.z, e), r: 0 }; }+ if (t < 37.3) return { x: WHOLE.x + 0.15 * (t - 35.35), y: WHOLE.y, z: WHOLE.z * (1 + 0.01 * (t - 35.35)), r: 0 };+ const a = { x: WHOLE.x + 0.3, y: WHOLE.y, z: WHOLE.z * 1.02 }, b = camVerdictBase, e = eio(seg(t, 37.3, 38.6));+ if (t >= 38.6) { const d = 1 - ss(seg(t, 42.1, 42.8)); return { x: b.x + d * 0.15, y: b.y, z: ZC * (1 - 0.006 * d), r: 0 }; }+ return { x: lerp(a.x, b.x, e), y: lerp(a.y, b.y, e), z: logLerp(a.z, b.z, e), r: 0 };+};++// the pull-out: from the charger through every board to the whole corridor board on the desk+function camUp(name, cam) { let c = cam, n = name; while (LV[n].parent) { c = toParent(c, LV[n]); n = LV[n].parent; } return c; }+function camDown(cam0) { let c = cam0; for (const n of ['city', 'house', 'charger']) c = toChild(c, LV[n]); return c; }+const PULL0 = 52.9, PULL1 = 54.5;+const START = camUp('charger', camVerdictBase);+const DB_L0 = camUp('charger', { x: CH.DB1.c[0], y: CH.DB1.c[1], z: 1, r: 0 });+const ZE = 0.8, RE = -0.03, BC = [1010, 470];+const endCam = t => { const k = 1 + 0.04 * ss(seg(t, PULL1, DUR)); return { x: BC[0], y: BC[1], z: ZE * k, r: RE * (1 + 0.15 * ss(seg(t, PULL1, DUR))) }; };+const sEnd = toScreen(camMatrix(endCam(PULL1)), [DB_L0.x, DB_L0.y]);+const camPull = t => {+ if (t >= PULL1) return endCam(t);+ const p = seg(t, PULL0, PULL1), e = 1 - Math.pow(1 - p, 2.6);+ const z = logLerp(START.z, ZE, e), r = RE * ss(seg(t, PULL0 + 0.8, PULL1));+ const sp = [lerp(DBPOS[0], sEnd[0], ss(p)), lerp(DBPOS[1], sEnd[1], ss(p))];+ return camFor([DB_L0.x, DB_L0.y], sp, z, r);+};++// ======================= shots =======================+const SHOTS = [+ { t0: 0, t1: 4.7, level: 'corridor', cam: camDam },+ { t0: 4.7, t1: 10.1, level: 'corridor', cam: camBus },+ { t0: 10.1, t1: 14.4, level: 'loss', cam: camLoss },+ { t0: 14.4, t1: 18.75, level: 'corridor', cam: camButuo },+ { t0: 18.75, t1: 19.1, level: 'corridor', cam: camWhip },+ { t0: 19.1, t1: 23.5, level: 'corridor', cam: camCorr },+ { t0: 23.5, t1: 29.6, level: 'corridor', cam: camYuch },+ ...CUTS.map((c, k) => ({ t0: c.t0, t1: c.t0 + 0.7, level: c.level, cam: t => camCut(k, t) })),+ { t0: 32.4, t1: 34.6, level: 'house', cam: camStreet },+ { t0: 34.6, t1: PULL0, level: 'charger', cam: camCharger },+ { t0: PULL0, t1: DUR + 1, level: 'corridor', cam: camPull, deep: true },+];+const shotOf = t => SHOTS.find(s => t >= s.t0 && t < s.t1) || SHOTS[SHOTS.length - 1];+const blurGroup = s => s.t1 <= 10.1 ? [0, 10.1] : (s.t0 >= 14.4 && s.t1 <= 29.6) ? [14.4, 29.6] : [s.t0, s.t1];++// ======================= scene: the corridor board =======================+// [start, plot time, end] — labels plot stroke by stroke and stay until `end` (if given)+const PLOT_C = { title: [0.6, 0.7], titleE: [0.95, 0.6], acBus: [6.4, 0.5], acBusE: [6.6, 0.3],+ acIn: [14.6, 0.5], acInE: [14.8, 0.3], csB: [15.3, 0.6], csBE: [15.5, 0.5], dcOut: [16.7, 0.5], dcOutE: [16.85, 0.3],+ sc: [19.1, 0.4], scE: [19.3, 0.35], len: [20.5, 0.6], lenE: [20.7, 0.4], js: [20.6, 0.4], jsE: [20.8, 0.35],+ csY: [23.5, 0.5], csYE: [23.7, 0.4], ms7: [24.0, 0.45], ms7E: [24.2, 0.3], acOut: [27.2, 0.45, 29.6], acOutE: [27.35, 0.3, 29.6],+ step: [29.6, 0.35], stepE: [29.7, 0.3],+ tbBox: [54.4, 0.8], tb: [54.8, 0.8], tbE: [55.3, 0.6], sign: [56.0, 0.7] };+const plot = (tab, t) => { const o = {}; for (const [id, [t0, d, t1]] of Object.entries(tab)) o[id] = t1 !== undefined && t > t1 ? 0 : clamp((t - t0) / d); return o; };+function sceneCorridor(t, opt = {}) {+ const sc = { t, labels: plot(PLOT_C, t), gens: {}, ac: [], dc: [], glow: [], flashes: [] };+ const pen = {};+ for (const g of CW.GENS) pen[penOf(g).id] = clamp((t - (tGen(g.id) - PEN_T)) / PEN_T);+ sc.water = { res: 1, up: 1, river: t < 10.1 ? 0.75 : 0.6, tail: clamp((t - 0.2) / 1.2), pen, penA: 1 };+ for (const g of CW.GENS) {+ const dt = t - tGen(g.id); if (dt < 0) continue;+ sc.gens[g.id] = 0.16 + 0.84 * Math.exp(-dt / 0.18);+ sc.flashes.push({ p: [g.x, g.y], r: 5.5 * CW.DS, a: 0.22, c: { h: [255, 214, 140], g: [255, 170, 60] } });+ if (dt < 0.4) sc.flashes.push({ p: [g.x, g.y], r: 9 * CW.DS, a: Math.exp(-dt / 0.12) });+ const lead = T('lead' + g.id); sc.ac.push({ trace: lead, s0: 0, s1: lead.m.len * clamp(dt / 0.12), a: 1, lam: 1.7 * CW.DS, phase: acPhase(t) });+ }+ const tR = tGen('G1'), tL = tGen('G9');+ if (t > tR + 0.1) sc.ac.push({ trace: BARR, s1: BARR.m.len * clamp((t - tR - 0.1) / 1.6), a: 1, lam: 3.4 * CW.DS, phase: acPhase(t) });+ if (t > tL + 0.1) sc.ac.push({ trace: BARL, s1: BARL.m.len * clamp((t - tL - 0.1) / 1.6), a: 1, lam: 3.4 * CW.DS, phase: acPhase(t) });+ const slow = t >= 5.0 && t < 10.1; // the close-up: big, slow swing+ if (t > 1.2) sc.ac.push({ trace: ACR, s1: fR(Math.min(t, 4.9)), a: 1, lam: slow ? 8 : 4.2, amp: slow ? 0.42 : 0.32, phase: acPhase(t) });+ if (t > 15.0) sc.ac.push({ trace: ACB2, s1: fB2(t), a: 1, lam: 4.2, phase: acPhase(t) });+ if (t > 1.4) sc.ac.push({ trace: ACL, s1: ACL.m.len * clamp((t - 1.4) / 1.4), a: 1, lam: 4.2, phase: acPhase(t) });+ if (t > T_IN - 0.2) {+ const k = clamp((t - T_IN + 0.2) / 0.3);+ for (const e of CW.BUTUO.flow.all) sc.glow.push({ pts: e, w: 0.55, a: 0.55 * k * (0.75 + 0.25 * Math.sin(2 * Math.PI * 2.2 * t)) });+ if (t < T_IN + 0.5) sc.flashes.push({ p: BT, r: 9, a: Math.sin(Math.PI * clamp((t - T_IN + 0.2) / 0.7)) * 0.7 });+ }+ if (t > 16.5) { const h = headS(Math.min(t, T_ARR)); for (const tr of [DCP, DCN]) sc.dc.push({ trace: tr, head: h, a: 0.95, decay: t > T_ARR ? 2000 : 520, floor: 0.7, v: 200, maxPx: 60, minPx: 6.5 }); }+ for (const tp of CW.TPS) { const th = headT(tp.s); if (t > th && t < th + 0.5) sc.flashes.push({ p: tp.p, r: 9, a: 1 - (t - th) / 0.5 }); }+ if (t > T_ARR) {+ const k = clamp((t - T_ARR) / 0.3);+ for (const e of CW.YUCHENG.flow.all) sc.glow.push({ pts: e, w: 0.55, a: 0.55 * k * (0.75 + 0.25 * Math.sin(2 * Math.PI * 2.2 * t)) });+ if (t < T_ARR + 0.6) sc.flashes.push({ p: YC, r: 12, a: Math.sin(Math.PI * clamp((t - T_ARR) / 0.6)) * 0.9 });+ const fy = s => clamp((t - s) / 1.0);+ sc.ac.push({ trace: T('acY'), s1: T('acY').m.len * fy(T_AC), a: 1, lam: 3.4, phase: acPhase(t) }, { trace: T('acY2'), s1: T('acY2').m.len * fy(T_AC + 0.6), a: 1, lam: 3.4, phase: acPhase(t) },+ { trace: T('acY3'), s1: T('acY3').m.len * fy(T_AC + 1.2), a: 1, lam: 1.8, phase: acPhase(t) });+ }+ if (opt.bubble) { sc.labels = {}; sc.dc.forEach(d => { d.decay = 1e9; d.a = 0.8; d.minPx = 3.6; }); }+ return sc;+}+// ======================= scene: the loss board =======================+function sceneLoss(t) {+ const sc = { t, labels: plot({ loss: [11.4, 0.5], lossE: [11.6, 0.4] }, t), ac: [], dc: [], glow: [], flashes: [] };+ sc.ac.push({ trace: LS.byId('ac'), a: 1, fade: 260, x0: 520, lam: 84, v: 150 });+ return sc;+}+// ======================= scene: city and street =======================+const PLOT_CT = { step2: [29.6, 0.35], stepE2: [29.7, 0.3], step3: [29.6, 0.35], stepE3: [29.7, 0.3] };+function sceneCity(t) {+ const sc = { t, labels: plot(PLOT_CT, t), ac: [], dc: [], glow: [], flashes: [], lit: 0.8 };+ for (const id of ['in', 'c1', 'c2']) sc.ac.push({ trace: CT.byId(id), a: 1, lam: CT.byId(id).w * 4.2, phase: acPhase(t) });+ return sc;+}+function sceneHouse(t) {+ const sc = { t, labels: plot({ step4: [29.6, 0.35], stepE4: [29.7, 0.3] }, t), ac: [], dc: [], glow: [], flashes: [], lit: 1 };+ for (const tr of HS.TRACES) {+ if (tr.net !== 'ac') continue;+ const s1 = tr.id === 'sock' ? tr.m.len * clamp((t - 32.7) / 1.1) : tr.m.len;+ sc.ac.push({ trace: tr, s1, a: 1, lam: Math.max(tr.w * 4.2, 3), phase: acPhase(t) });+ }+ if (t > 33.75) sc.flashes.push({ p: [SK.holeL[0], SK.holeL[1] - 9], r: 8, a: clamp((t - 33.75) / 0.2) * 0.9 });+ return sc;+}+// ======================= scene: the charger =======================+const PLOT_H3 = { chg: [35.3, 0.5], chgE: [35.45, 0.35], zlq: [38.5, 0.45], zlqE: [38.65, 0.4], acdc: [39.9, 0.45, 42.9], acdcE: [40.05, 0.35, 42.9],+ csV: [42.9, 0.45], csVE: [43.05, 0.4], eq: [47.6, 0.25], same: [47.7, 0.6], sameE: [47.9, 0.4], x4: [49.4, 0.55], x4E: [49.6, 0.4] };+const CB = id => CH.byId(id);+const T_DB = 39.4;+function sceneCharger(t) {+ const sc = { t, labels: plot(PLOT_H3, t), ac: [], dc: [], glow: [], flashes: [] };+ const tt = Math.max(t, 34.6);+ sc.ac.push({ trace: CB('pL'), s1: CB('pL').m.len * clamp((tt - 34.7) / 0.5), a: 1, lam: 1.7, phase: acPhase(t) }, { trace: CB('L'), s1: CB('L').m.len * clamp((tt - 35.2) / 0.9), a: 1, lam: 1.7, phase: acPhase(t) }, { trace: CB('L2'), s1: CB('L2').m.len * clamp((tt - 37.6) / 1.4), a: 1, lam: 1.7, phase: acPhase(t) });+ if (t > T_DB - 0.2) {+ const fl = t >= 47.6 ? Math.exp(-(t - 47.6) / 0.35) : 0, k = clamp((t - T_DB + 0.2) / 0.3);+ for (const e of CH.DB1.flow.all) sc.glow.push({ pts: e, w: 0.35 * CH.K, a: (0.5 + 0.5 * fl) * k });+ if (t < T_DB + 0.5) sc.flashes.push({ p: CH.DB1.c, r: 6, a: Math.sin(Math.PI * clamp((t - T_DB + 0.2) / 0.7)) * 0.7 });+ if (fl > 0.01) sc.flashes.push({ p: CH.DB1.c, r: 6, a: 0.8 * fl });+ }+ const run = (id, t0, dur) => { const tr = CB(id); if (t > t0) sc.dc.push({ trace: tr, head: tr.m.len * clamp((t - t0) / dur), a: 0.8, headGlow: t < t0 + dur, v: 14, floor: 1, maxPx: 40 }); };+ run('plus', T_DB + 0.2, 0.7); run('minus', T_DB + 0.2, 0.7); run('pri', T_DB + 0.8, 0.5); run('sec', T_DB + 1.4, 0.4); run('vbus', T_DB + 1.8, 0.4);+ if (t >= 42.1) sc.after = (g, M, z) => drawBubble(g, M, z, t);+ return sc;+}+function drawBubble(g, M, z, t) {+ const open = clamp((t - 42.2) / 0.6) * (1 - clamp((t - 52.55) / 0.35));+ const B = CH.BUBBLE, c = toScreen(M, B.c), at_ = toScreen(M, B.at), r = B.r * z * eo(open);+ if (r < 1) return;+ const fl = t >= 47.6 ? Math.exp(-(t - 47.6) / 0.35) : 0;+ const cam = camFor(BT, at_, z * CH.K), sc = sceneCorridor(Math.max(t, 26), { bubble: true });+ sc.glow.forEach(q => q.a = Math.min(1, q.a + 0.5 * fl)); if (fl > 0.01) sc.flashes.push({ p: BT, r: 9, a: 0.8 * fl });+ bubbleBoard.frame(cam, sc);+ g.save(); g.setTransform(1, 0, 0, 1, 0, 0);+ g.beginPath(); g.arc(c[0], c[1], r, 0, 6.2832); g.save(); g.clip(); g.drawImage(bcv, 0, 0); g.restore();+ const sh = g.createRadialGradient(c[0], c[1], r * 0.82, c[0], c[1], r); sh.addColorStop(0, 'rgba(0,0,0,0)'); sh.addColorStop(1, 'rgba(0,0,0,0.38)');+ g.fillStyle = sh; g.fill(); g.lineWidth = 0.2 * z; g.strokeStyle = '#F2EEE1'; g.stroke();+ g.lineWidth = 0.08 * z; g.beginPath(); g.arc(c[0], c[1], r + 0.45 * z, 0, 6.2832); g.stroke();+ g.restore();+}+const SCENES = { corridor: sceneCorridor, city: sceneCity, house: sceneHouse, charger: sceneCharger, loss: sceneLoss };++// ======================= frame =======================+function stackAt(t) {+ const sh = shotOf(t); let cam = sh.cam(t), name = sh.level;+ if (sh.deep) { cam = camDown(cam); name = 'charger'; }+ const b = baseOf(LV, name, cam, W, H);+ return { sh, base: b.l, cam: b.cam };+}+function drawAt(t) {+ const { base, cam } = stackAt(t);+ drawLevel(LV, base, cam, n => SCENES[n](t), W, H);+ ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.globalAlpha = 1; ctx.drawImage(base.cv, 0, 0);+}+// depth of field: strong in macro moments without words, light where text must be read+const DOF = [[0, 0.8, 0.9], [0.8, 4.7, 0.15], [4.7, 10.1, 0.45], [10.1, 14.4, 0.12], [14.4, 19.1, 0.25], [19.1, 23.5, 0.08], [23.5, 29.6, 0.12], [29.6, 32.4, 0.5],+ [32.4, 34.6, 0.6], [34.6, 38.6, 0.35], [38.6, 52.9, 0.1], [52.9, 60, 0.05]];+function postFor(t, st) {+ const d = DOF.find(q => t >= q[0] && t < q[1]) || DOF[DOF.length - 1];+ const o = { t, dof: d[2], motes: t >= PULL1 ? 0.5 : 1, px: st.cam.x * st.cam.z, py: st.cam.y * st.cam.z };+ if (t > PULL1 - 0.6 && st.base.name === 'corridor') {+ const a = 0.5 * ss(seg(t, PULL1 - 0.6, PULL1 + 1.2)), m = 50 * (t - PULL1);+ o.window = { cam: st.cam, a, soft: 30, quad: [[60 + m, -200], [720 + m, -200], [420 + m, 1300], [-240 + m, 1300]], mullion: [[400 + m, -200], [430 + m, -200], [130 + m, 1300], [100 + m, 1300]] };+ }+ return o;+}+// subtitles: one cue per spoken line, Chinese over English, in the bottom safe area+const SUB_CN = 34, SUB_EN = 24, SUB_Y = 974;+function subBox(s) {+ ctx.font = `500 ${SUB_CN}px SubSC`; const wc = ctx.measureText(s.cn).width;+ ctx.font = `500 ${SUB_EN}px SubSC`; const we = ctx.measureText(s.en).width;+ return { wc, we, w: Math.max(wc, we) };+}+function drawSubs(t) {+ for (const s of SUBS) {+ const a = ss(seg(t, s.t0, s.t0 + 0.12)) * (1 - ss(seg(t, s.t1 - 0.12, s.t1))); if (a <= 0) continue;+ const b = subBox(s);+ ctx.save(); ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.globalAlpha = a;+ ctx.fillStyle = 'rgba(3,14,9,0.62)'; ctx.beginPath(); ctx.roundRect(W / 2 - b.w / 2 - 22, SUB_Y - SUB_CN - 14, b.w + 44, SUB_CN + SUB_EN + 38, 6); ctx.fill();+ ctx.textAlign = 'center'; ctx.textBaseline = 'alphabetic';+ ctx.fillStyle = '#F7F4EA'; ctx.font = `500 ${SUB_CN}px SubSC`; ctx.fillText(s.cn, W / 2, SUB_Y);+ ctx.fillStyle = 'rgba(247,244,234,0.86)'; ctx.font = `500 ${SUB_EN}px SubSC`; ctx.fillText(s.en, W / 2, SUB_Y + SUB_EN + 12);+ ctx.restore();+ }+}+const acc = new OffscreenCanvas(W, H), actx = acc.getContext('2d');+const SHUT = 1 / 60;+function motionPx(t, sh) {+ const [g0, g1] = blurGroup(sh), a = clamp(t - SHUT / 2, g0, g1 - 1e-4), b = clamp(t + SHUT / 2, g0, g1 - 1e-4);+ const sa = shotOf(a), sb = shotOf(b);+ if (sa.level !== sb.level || sa.deep) return sh.deep ? motionDeep(a, b) : 0;+ const ca = camMatrix(sa.cam(a)), Mb = camMatrix(sb.cam(b));+ const inv = (M, p) => { const det = M[0] * M[3] - M[1] * M[2], x = p[0] - M[4], y = p[1] - M[5]; return [(M[3] * x - M[2] * y) / det, (-M[1] * x + M[0] * y) / det]; };+ let m = 0; for (const p of [[0, 0], [W, 0], [0, H], [W, H], [W / 2, H / 2]]) { const w = inv(ca, p), q = toScreen(Mb, w); m = Math.max(m, Math.hypot(q[0] - p[0], q[1] - p[1])); }+ return m;+}+function motionDeep(a, b) { const za = camPull(a).z, zb = camPull(b).z; return Math.abs(LN(zb / za)) * 260; }+window.DUR = DUR;+const Q = new URLSearchParams(location.search);+window.render = t => {+ const sh = shotOf(t), [g0, g1] = blurGroup(sh), N = Math.min(sh.deep ? 6 : 20, Math.max(1, Math.ceil(motionPx(t, sh) / 2.6)));+ if (N <= 1) drawAt(t);+ else {+ for (let i = 0; i < N; i++) { const ti = clamp(t + (i / (N - 1) - 0.5) * SHUT, g0, g1 - 1e-4); drawAt(ti); actx.globalAlpha = 1 / (i + 1); actx.drawImage(cv, 0, 0); }+ actx.globalAlpha = 1; ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.drawImage(acc, 0, 0);+ }+ post(ctx, postFor(t, stackAt(t)));+ if (!Q.has('nosub')) drawSubs(t);+};+// every piece of text on screen, with its box (readcheck). Subtitles are reported only with ?subs=1:+// a spoken line is read along with the voice, not at the 4.5 characters/s the check assumes.+window.TEXTS = t => {+ const { base, cam } = stackAt(t), out = [];+ const walk = (l, c, clip) => {+ for (const b of l.board.texts(c, SCENES[l.name](t), l.name + ':')) { if (clip && (b.x0 < clip[0] || b.x1 > clip[2] || b.y0 < clip[1] || b.y1 > clip[3])) continue; out.push(b); }+ const M = camMatrix(c);+ for (const k of l.kids) {+ const B = k.world.BOARD, p0 = toScreen(M, [k.at[0] + B.x0 * k.s, k.at[1] + B.y0 * k.s]), p1 = toScreen(M, [k.at[0] + B.x1 * k.s, k.at[1] + B.y1 * k.s]);+ const r = [Math.min(p0[0], p1[0]), Math.min(p0[1], p1[1]), Math.max(p0[0], p1[0]), Math.max(p0[1], p1[1])];+ if (r[2] - r[0] > 3) walk(k, toChild(c, k), r);+ }+ };+ walk(base, cam, null);+ if (Q.get('subs') === '1') for (const s of SUBS) if (t >= s.t0 + 0.12 && t < s.t1 - 0.12) {+ const b = subBox(s);+ out.push({ id: 'sub:' + s.id, text: s.cn, x0: W / 2 - b.wc / 2, y0: SUB_Y - SUB_CN, x1: W / 2 + b.wc / 2, y1: SUB_Y + 8 }, { id: 'subE:' + s.id, text: s.en, x0: W / 2 - b.we / 2, y0: SUB_Y + 12, x1: W / 2 + b.we / 2, y1: SUB_Y + SUB_EN + 18 });+ }+ return out;+};+window.SUBS = SUBS;++// ======================= sound events (exported by events.mjs for audio.py) =======================+const EV = [{ t: 0, type: 'water' }];+for (const id of ORDER) EV.push({ t: Math.round(tGen(id) * 1000) / 1000, type: 'gen', i: ORDER.indexOf(id) });+for (const tab of [PLOT_C, PLOT_H3]) for (const [id, [t0, d]] of Object.entries(tab)) EV.push({ t: Math.round(t0 * 1000) / 1000, type: 'plot', d, big: ['title', 'tb', 'same', 'eq', 'ms7', 'x4'].includes(id) });+VO.forEach((t0, i) => EV.push({ t: t0, type: 'vo', id: VOTXT[i].id, d: DURS[VOTXT[i].id] }));+EV.push({ t: 4.7, type: 'hum' }, { t: 10.1, type: 'cut', i: 0 }, { t: 14.4, type: 'cut', i: 1 }, { t: T_IN, type: 'smooth', n: 0 }, { t: 18.75, type: 'whip' });+for (const tp of CW.TPS) EV.push({ t: Math.round(headT(tp.s) * 1000) / 1000, type: 'km' });+EV.push({ t: T_ARR, type: 'impact' }, { t: 24.0, type: 'bell', n: 91 }, { t: T_AC, type: 'chop' });+CUTS.forEach((c, i) => EV.push({ t: c.t0, type: 'step', i }));+EV.push({ t: 32.4, type: 'outside' }, { t: 34.0, type: 'suck' }, { t: 34.6, type: 'pop' }, { t: T_DB, type: 'smooth', n: 2 }, { t: 42.2, type: 'still' }, { t: 47.6, type: 'equal' },+ { t: PULL0, type: 'pullout' }, { t: 54.8, type: 'final' }, { t: 56.0, type: 'sign' }, { t: DUR, type: 'end' });+window.EV = EV.sort((a, b) => a.t - b.t);+window.READY = true;diff --git a/styles/circuit-board/demo/src/palette.js b/styles/circuit-board/demo/src/palette.jsnew file mode 100644index 0000000..cbbd606--- /dev/null+++ b/styles/circuit-board/demo/src/palette.js@@ -0,0 +1,17 @@+// The look: green solder mask, ENIG gold, bare copper for the dam, white silkscreen,+// amber current, silver water. Every colour the renderer uses comes from here.+export const rgb = (c, a = 1) => `rgba(${c[0]},${c[1]},${c[2]},${a})`;+export const PAL = {+ bg: '#05190F', weaveA: 'rgba(120,200,150,0.045)', weaveA2: 'rgba(120,200,150,0.03)', weaveB: 'rgba(0,0,0,0.10)',+ under: 'rgba(60,140,96,0.22)', // bottom-layer copper seen through the laminate+ pour: { fill: '#1C6A44', rim: '#4AA977' },+ fence: { ring: 'rgba(63,158,108,0.85)', hole: 'rgba(3,18,11,0.85)' },+ trace: { rim: '#4AA977', fill: '#2B8158' },+ pad: { fill: '#D9B25B', edge: '#A07B30', sheen: 'rgba(255,240,190,0.28)', hole: '#06130D' },+ copper: { hi: '#F2B184', mid: '#C9784A', lo: '#8F4C27', edge: '#6E3A1E' },+ silk: '#F2EEE1',+ cur: { g: [255, 190, 84], h: [255, 236, 180], e: [255, 196, 110] },+ water: { g: [170, 214, 226], h: [228, 246, 252] },+ vig: 'rgba(0,10,6,0.55)',+ desk: '#0B0D0C', deskHi: 'rgba(52,56,50,0.45)',+};diff --git a/styles/circuit-board/demo/src/parts.js b/styles/circuit-board/demo/src/parts.jsnew file mode 100644index 0000000..d4ace4b--- /dev/null+++ b/styles/circuit-board/demo/src/parts.js@@ -0,0 +1,145 @@+// Footprint builders shared by every board. Each returns primitives the renderer knows:+// pads (gold), silk (polylines / dots), keep (copper clearances), glow paths (for current), plus anchor points.+import { textWidth } from './font.js';++export const box = (x0, y0, x1, y1) => [[x0, y0], [x1, y0], [x1, y1], [x0, y1], [x0, y0]];+const chamferBox = (x0, y0, x1, y1, c) => [[x0 + c, y0], [x1, y0], [x1, y1], [x0, y1], [x0, y0 + c], [x0 + c, y0]];++// A diode drawn on an edge from a to b (anode -> cathode): triangle pointing to b, bar at its tip.+function diode(a, b, s) {+ const dx = b[0] - a[0], dy = b[1] - a[1], L = Math.hypot(dx, dy), ux = dx / L, uy = dy / L, nx = -uy, ny = ux;+ const m = [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2], h = s * 0.5;+ const base = [m[0] - ux * h, m[1] - uy * h], tip = [m[0] + ux * h, m[1] + uy * h];+ return {+ tri: [[base[0] + nx * h, base[1] + ny * h], [tip[0], tip[1]], [base[0] - nx * h, base[1] - ny * h], [base[0] + nx * h, base[1] + ny * h]],+ bar: [[tip[0] + nx * h, tip[1] + ny * h], [tip[0] - nx * h, tip[1] - ny * h]],+ lead: [[a[0], a[1]], [base[0], base[1]], null, [tip[0], tip[1]], [b[0], b[1]]],+ };+}++// The bridge: a square package turned 45 degrees (a diamond), one pad at each vertex.+// AC in at the left vertex, the return at the right vertex, + at the top, − at the bottom.+// Diodes on the four edges point from − to + . R = centre-to-vertex.+export function bridge(c, R, o = {}) {+ const [x, y] = c, L = [x - R, y], T = [x, y - R], Rv = [x + R, y], B = [x, y + R];+ const pr = R * 0.17, sw = o.sw ?? R * 0.055, ds = R * 0.32;+ const pads = [L, T, Rv, B].map(([px, py], i) => ({ x: px, y: py, r: pr, shape: 'round', hole: o.th ? pr * 0.42 : 0, id: (o.id || 'br') + ':' + 'LTRB'[i] }));+ const silk = [];+ const k = R + pr * 1.9; // silk outline just outside the pads+ silk.push({ pts: [[x - k, y], [x, y - k], [x + k, y], [x, y + k], [x - k, y]], w: sw });+ // inner diamond with the four diodes: L->T, R->T (into +), B->L, B->R (from −)+ const q = R - pr * 1.6, Li = [x - q, y], Ti = [x, y - q], Ri = [x + q, y], Bi = [x, y + q];+ for (const [a, b] of [[Li, Ti], [Ri, Ti], [Bi, Li], [Bi, Ri]]) {+ const d = diode(a, b, ds);+ silk.push({ pts: d.tri, w: sw, fill: true }, { pts: d.bar, w: sw * 1.2 });+ silk.push({ pts: [d.lead[0], d.lead[1]], w: sw }, { pts: [d.lead[3], d.lead[4]], w: sw });+ }+ // terminal marks+ const mk = R * 0.2, mo = pr * 2.6;+ silk.push({ tilde: [x - R - mo - mk * 0.2, y - pr * 2.4], s: mk, w: sw });+ silk.push({ tilde: [x + R + mo * 0.15, y - pr * 2.4], s: mk, w: sw });+ const px = x + R * 0.98, py = y - R - pr - mk * 0.75, ny = y + R + pr + mk * 0.75;+ silk.push({ pts: [[px, py], [px + mk, py]], w: sw }, { pts: [[px + mk / 2, py - mk / 2], [px + mk / 2, py + mk / 2]], w: sw });+ silk.push({ pts: [[px, ny], [px + mk, ny]], w: sw });+ const keep = [{ poly: [[x - k - pr, y], [x, y - k - pr], [x + k + pr, y], [x, y + k + pr]] }];+ // the paths current takes through the symbol (for the glow): in at L, out at T (+) ; return B -> R+ const flow = { plus: [L, Li, Ti, T], minus: [B, Bi, Ri, Rv], all: [[Li, Ti], [Ri, Ti], [Bi, Li], [Bi, Ri]] };+ return { pads, silk, keep, L, T, R: Rv, B, flow, c, Rad: R };+}++// Ground symbol (silk) hanging from point p, pointing right+export function ground(p, s, sw, dir = 1) {+ const [x, y] = p, X = k => x + dir * s * k;+ return [+ { pts: [[x, y], [X(0.8), y]], w: sw },+ { pts: [[X(0.8), y - s * 0.7], [X(0.8), y + s * 0.7]], w: sw },+ { pts: [[X(1.15), y - s * 0.45], [X(1.15), y + s * 0.45]], w: sw },+ { pts: [[X(1.5), y - s * 0.2], [X(1.5), y + s * 0.2]], w: sw },+ ];+}++// A two-pad chip (fuse, resistor, ceramic cap): centre, length along x, pad size+export function chip(c, len, pw, ph, o = {}) {+ const [x, y] = c, sw = o.sw ?? ph * 0.09;+ const pads = [{ x: x - len / 2, y, w: pw, h: ph, shape: 'rect', r: ph * 0.12 }, { x: x + len / 2, y, w: pw, h: ph, shape: 'rect', r: ph * 0.12 }];+ const bx = len / 2 + pw / 2 + sw * 2.5, by = ph / 2 + sw * 2.5;+ const silk = [{ pts: [[x - bx + pw * 0.9, y - by], [x + bx - pw * 0.9, y - by]], w: sw }, { pts: [[x - bx + pw * 0.9, y + by], [x + bx - pw * 0.9, y + by]], w: sw }];+ const keep = [{ rect: [x - bx, y - by, x + bx, y + by] }];+ return { pads, silk, keep, a: [x - len / 2, y], b: [x + len / 2, y] };+}++// Electrolytic capacitor footprint: silk circle with a hatched − half, two round pads+export function ecap(c, r, o = {}) {+ const [x, y] = c, sw = o.sw ?? r * 0.045, pr = r * 0.2, d = r * 0.42;+ const pads = [{ x: x - d, y, r: pr, shape: 'square', hole: pr * 0.45 }, { x: x + d, y, r: pr, shape: 'round', hole: pr * 0.45 }];+ const silk = [{ circle: [x, y, r], w: sw }];+ for (let i = 1; i <= 5; i++) { const xx = x + r * (0.32 + i * 0.12); const hh = Math.sqrt(Math.max(0, r * r - (xx - x) ** 2)) * 0.96; silk.push({ pts: [[xx, y - hh], [xx, y + hh]], w: sw * 0.8 }); }+ silk.push({ pts: [[x - r * 0.62, y - r * 0.62], [x - r * 0.38, y - r * 0.62]], w: sw }, { pts: [[x - r * 0.5, y - r * 0.74], [x - r * 0.5, y - r * 0.5]], w: sw });+ return { pads, silk, keep: [{ circle: [x, y, r + sw * 2] }], plus: [x - d, y], minus: [x + d, y] };+}++// Transformer: rectangular bobbin outline, two winding symbols, pins on both sides+export function xfmr(c, w, h, n, o = {}) {+ const [x, y] = c, sw = o.sw ?? h * 0.022, pr = h * 0.06;+ const pads = [], pin = (s, i) => [x + s * w / 2, y - h / 2 + h * (i + 0.5) / n];+ for (let i = 0; i < n; i++) for (const s of [-1, 1]) pads.push({ x: pin(s, i)[0], y: pin(s, i)[1], r: pr, shape: i === 0 && s < 0 ? 'square' : 'round', hole: pr * 0.45 });+ const silk = [{ pts: box(x - w / 2 + pr * 2.2, y - h / 2 - pr * 0.6, x + w / 2 - pr * 2.2, y + h / 2 + pr * 0.6), w: sw }];+ // windings: bumps (primary left, secondary right) and the core bars+ const bump = (cx, dir) => { const pts = []; const r = h * 0.07; for (let k = 0; k < 4; k++) { const cy = y - h * 0.28 + k * r * 2; for (let a = 0; a <= 8; a++) { const an = -Math.PI / 2 + Math.PI * a / 8; pts.push([cx + dir * Math.cos(an) * r, cy + r + Math.sin(an) * r]); } } return pts; };+ silk.push({ pts: bump(x - w * 0.12, -1), w: sw }, { pts: bump(x + w * 0.12, 1), w: sw });+ silk.push({ pts: [[x - w * 0.03, y - h * 0.3], [x - w * 0.03, y + h * 0.3]], w: sw }, { pts: [[x + w * 0.03, y - h * 0.3], [x + w * 0.03, y + h * 0.3]], w: sw });+ return { pads, silk, keep: [{ rect: [x - w / 2 - pr * 2, y - h / 2 - pr * 2, x + w / 2 + pr * 2, y + h / 2 + pr * 2] }], pin };+}++// The step-down transformer symbol used in the city cut: two coils facing, as copper-and-silk art+export function xsym(c, s, ratio, sw) {+ const [x, y] = c, silk = [];+ const coil = (cx, n, dir) => { const pts = []; const r = s * 0.42 / n; for (let k = 0; k < n; k++) { const cy = y - s * 0.42 + k * 2 * r; for (let a = 0; a <= 10; a++) { const an = -Math.PI / 2 + Math.PI * a / 10; pts.push([cx + dir * Math.cos(an) * r, cy + r + Math.sin(an) * r]); } } return pts; };+ silk.push({ pts: coil(x - s * 0.18, ratio[0], -1), w: sw }, { pts: coil(x + s * 0.18, ratio[1], 1), w: sw });+ silk.push({ pts: [[x - s * 0.04, y - s * 0.46], [x - s * 0.04, y + s * 0.46]], w: sw }, { pts: [[x + s * 0.04, y - s * 0.46], [x + s * 0.04, y + s * 0.46]], w: sw });+ return silk;+}++// A small silk frame with a label inside (timestamps)+export function tag(x, y, text, cap, sw, padX = 0.9, padY = 0.75) {+ const tw = textWidth(text, cap);+ return { frame: chamferBox(x - cap * padX, y - cap * padY, x + tw + cap * padX, y + cap * (1 + padY), cap * 0.45), w: sw, text: { text, x, y, cap }, width: tw + 2 * cap * padX };+}++// An in-line transformer footprint (horizontal: in on the left, out on the right), size s = body width.+// ratio = [primary bumps, secondary bumps]; the coils are silkscreen, the two terminals are pads.+export function xformer(c, s, ratio, sw, o = {}) {+ const [x, y] = c, h = s * 0.82, pw = s * 0.12, ph = s * 0.22;+ const inP = [x - s / 2, y], outP = [x + s / 2, y];+ const pads = [{ x: inP[0], y, w: pw, h: ph, shape: 'rect', r: pw * 0.2 }, { x: outP[0], y, w: pw, h: ph, shape: 'rect', r: pw * 0.2 }];+ const silk = [{ pts: chamferBox(x - s / 2 + pw, y - h / 2, x + s / 2 - pw, y + h / 2, s * 0.08), w: sw }];+ const coil = (cx, n, dir) => { const pts = [[cx, y - h * 0.38]]; const r = h * 0.38 / n; for (let k = 0; k < n; k++) { const cy = y - h * 0.38 + k * 2 * r; for (let a = 0; a <= 10; a++) { const an = -Math.PI / 2 + Math.PI * a / 10; pts.push([cx + dir * Math.cos(an) * r, cy + r + Math.sin(an) * r]); } } return pts; };+ silk.push({ pts: coil(x - s * 0.12, ratio[0], -1), w: sw }, { pts: coil(x + s * 0.12, ratio[1], 1), w: sw });+ silk.push({ pts: [[x - s * 0.03, y - h * 0.42], [x - s * 0.03, y + h * 0.42]], w: sw }, { pts: [[x + s * 0.03, y - h * 0.42], [x + s * 0.03, y + h * 0.42]], w: sw });+ // leads from the pads into the coils+ silk.push({ pts: [[inP[0] + pw / 2, y], [x - s * 0.2, y]], w: sw * 0.7, dash: [sw * 2, sw * 2] }, { pts: [[outP[0] - pw / 2, y], [x + s * 0.2, y]], w: sw * 0.7, dash: [sw * 2, sw * 2] });+ return { pads, silk, keep: [{ rect: [x - s / 2 - pw, y - h / 2 - sw, x + s / 2 + pw, y + h / 2 + sw] }], inP, outP, c, s };+}+// A smoothing reactor sitting on a horizontal trace: two pads and a row of silk bumps above (dir -1) or below (+1)+export function reactor(c, len, sw, dir = -1) {+ const [x, y] = c, pw = len * 0.16, ph = len * 0.3;+ const pads = [{ x: x - len / 2, y, w: pw, h: ph, shape: 'rect', r: pw * 0.2 }, { x: x + len / 2, y, w: pw, h: ph, shape: 'rect', r: pw * 0.2 }];+ const n = 4, r = (len - pw * 1.6) / (2 * n), pts = [];+ for (let k = 0; k < n; k++) { const cx = x - len / 2 + pw * 0.8 + r + k * 2 * r; for (let a = 0; a <= 8; a++) { const an = Math.PI + Math.PI * a / 8; pts.push([cx + Math.cos(an) * r * -1 * -1, y + dir * (ph * 0.9) + dir * -Math.sin(an) * r]); } }+ return { pads, silk: [{ pts, w: sw }], keep: [] };+}+// A bank of small chip capacitors hanging off a horizontal line at height y, to a ground rail+export function capBank(x0, y, n, pitch, len, sw, dir = 1) {+ const pads = [], silk = [], traces = [];+ for (let i = 0; i < n; i++) {+ const x = x0 + i * pitch, a = y + dir * len * 0.55, b = y + dir * len * 1.35;+ pads.push({ x, y: a, w: len * 0.38, h: len * 0.28, shape: 'rect', r: len * 0.05 }, { x, y: b, w: len * 0.38, h: len * 0.28, shape: 'rect', r: len * 0.05 });+ silk.push({ pts: [[x - len * 0.32, (a + b) / 2], [x + len * 0.32, (a + b) / 2]], w: sw }, { pts: [[x - len * 0.32, (a + b) / 2 + dir * len * 0.1], [x + len * 0.32, (a + b) / 2 + dir * len * 0.1]], w: sw });+ traces.push([[x, y], [x, a]]);+ }+ const rail = y + dir * len * 1.7;+ for (let i = 0; i < n; i++) traces.push([[x0 + i * pitch, y + dir * len * 1.35], [x0 + i * pitch, rail]]);+ traces.push([[x0 - pitch * 0.3, rail], [x0 + (n - 1) * pitch + pitch * 0.3, rail]]);+ return { pads, silk, traces, rail };+}+export { chamferBox };diff --git a/styles/circuit-board/demo/src/post.js b/styles/circuit-board/demo/src/post.jsnew file mode 100644index 0000000..6c4f9bc--- /dev/null+++ b/styles/circuit-board/demo/src/post.js@@ -0,0 +1,54 @@+// Screen-space finishing, applied once per frame on top of the board stack:+// a soft key light, shallow depth of field at the top and bottom of frame (macro lens), out-of-focus motes of+// light in front of the board, the noon window light at the end, and the vignette.+import { camMatrix } from './render.js';+import { mulberry } from '/core/lib.js';++export function makePost(W, H) {+ const blur = new OffscreenCanvas(W, H), bg = blur.getContext('2d');+ const r = mulberry(23), motes = [];+ for (let i = 0; i < 26; i++) motes.push({ x: r() * W, y: r() * H, rad: 14 + r() * 46, a: 0.025 + r() * 0.05, par: 1.25 + r() * 0.9, warm: r() < 0.6 });+ return function post(ctx, o) {+ ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.globalAlpha = 1; ctx.filter = 'none';+ // depth of field: a blurred copy faded in toward the top and bottom edges+ if (o.dof > 0.01) {+ bg.setTransform(1, 0, 0, 1, 0, 0); bg.globalCompositeOperation = 'source-over'; bg.clearRect(0, 0, W, H);+ bg.filter = `blur(${(2 + 7 * o.dof).toFixed(1)}px)`; bg.drawImage(ctx.canvas, 0, 0); bg.filter = 'none';+ bg.globalCompositeOperation = 'destination-in';+ const g = bg.createLinearGradient(0, 0, 0, H), f = 0.12 + 0.12 * o.dof;+ g.addColorStop(0, 'rgba(0,0,0,1)'); g.addColorStop(f * 0.55, 'rgba(0,0,0,0.55)'); g.addColorStop(f, 'rgba(0,0,0,0)');+ g.addColorStop(1 - f, 'rgba(0,0,0,0)'); g.addColorStop(1 - f * 0.55, 'rgba(0,0,0,0.55)'); g.addColorStop(1, 'rgba(0,0,0,1)');+ bg.fillStyle = g; bg.fillRect(0, 0, W, H); bg.globalCompositeOperation = 'source-over';+ ctx.drawImage(blur, 0, 0);+ }+ // key light: a broad warm pool from the upper left, drifting slowly+ const lx = W * (0.3 + 0.06 * Math.sin(o.t * 0.21)), ly = H * (0.22 + 0.04 * Math.cos(o.t * 0.17));+ let g = ctx.createRadialGradient(lx, ly, 0, lx, ly, W * 0.75);+ g.addColorStop(0, 'rgba(255,246,220,0.10)'); g.addColorStop(0.5, 'rgba(255,246,220,0.035)'); g.addColorStop(1, 'rgba(255,246,220,0)');+ ctx.globalCompositeOperation = 'screen'; ctx.fillStyle = g; ctx.fillRect(0, 0, W, H);+ // out-of-focus motes in front of the board: they move faster than the board (parallax)+ if (o.motes > 0.01) {+ for (const m of motes) {+ const x = ((m.x - o.px * m.par) % (W + 200) + W + 200) % (W + 200) - 100, y = ((m.y - o.py * m.par) % (H + 200) + H + 200) % (H + 200) - 100;+ const c = m.warm ? '255,206,130' : '210,240,250', gg = ctx.createRadialGradient(x, y, m.rad * 0.55, x, y, m.rad);+ gg.addColorStop(0, `rgba(${c},${m.a * o.motes})`); gg.addColorStop(0.85, `rgba(${c},${m.a * o.motes * 0.8})`); gg.addColorStop(1, `rgba(${c},0)`);+ ctx.fillStyle = gg; ctx.beginPath(); ctx.arc(x, y, m.rad, 0, 6.2832); ctx.fill();+ }+ }+ // noon window light (board space): a parallelogram of warm light with one mullion shadow+ if (o.window && o.window.a > 0.005) {+ const M = camMatrix(o.window.cam), q = o.window.quad;+ ctx.save(); ctx.setTransform(...M); ctx.filter = `blur(${o.window.soft}px)`;+ ctx.globalCompositeOperation = 'soft-light'; ctx.beginPath(); ctx.moveTo(...q[0]); for (const p of q.slice(1)) ctx.lineTo(...p); ctx.closePath();+ ctx.fillStyle = `rgba(255,232,190,${o.window.a})`; ctx.fill();+ ctx.globalCompositeOperation = 'screen'; ctx.fillStyle = `rgba(255,226,180,${o.window.a * 0.16})`; ctx.fill();+ ctx.globalCompositeOperation = 'multiply'; const mq = o.window.mullion; ctx.beginPath(); ctx.moveTo(...mq[0]); for (const p of mq.slice(1)) ctx.lineTo(...p); ctx.closePath();+ ctx.fillStyle = `rgba(40,50,46,${o.window.a * 0.9})`; ctx.fill();+ ctx.restore(); ctx.filter = 'none';+ }+ ctx.globalCompositeOperation = 'source-over';+ // vignette+ g = ctx.createRadialGradient(W / 2, H * 0.48, H * 0.36, W / 2, H / 2, H * 1.05);+ g.addColorStop(0, 'rgba(0,0,0,0)'); g.addColorStop(1, 'rgba(0,10,6,0.58)'); ctx.fillStyle = g; ctx.fillRect(0, 0, W, H);+ };+}diff --git a/styles/circuit-board/demo/src/render.js b/styles/circuit-board/demo/src/render.jsnew file mode 100644index 0000000..343bd35--- /dev/null+++ b/styles/circuit-board/demo/src/render.js@@ -0,0 +1,403 @@+// Board renderer: draws one board (a world module) through a world -> screen camera, PCB layers bottom-up:+// laminate, copper pour with clearances (rim + fill), traces, exposed metal, silkscreen, then light+// (water in silver, current in amber) on an additive layer with a two-radius bloom.+// Level of detail: textures crossfade between octaves; small features fade before they go sub-pixel.+import { drawText, layout } from './font.js';+import { sub, at, measure, offset } from './geo.js';+import { PAL, rgb } from './palette.js';++let W = 1920, H = 1080;+export function setSize(w, h) { W = w; H = h; }+const clamp = (x, a = 0, b = 1) => Math.max(a, Math.min(b, x));+const sstep = (a, b, x) => { const t = clamp((x - a) / (b - a)); return t * t * (3 - 2 * t); };++// ---------- camera ----------+export function camMatrix(cam) {+ const s = cam.z, co = Math.cos(cam.r || 0), si = Math.sin(cam.r || 0);+ const a = s * co, b = s * si, c = -s * si, d = s * co;+ return [a, b, c, d, W / 2 - (a * cam.x + c * cam.y), H / 2 - (b * cam.x + d * cam.y)];+}+export const toScreen = (M, p) => [M[0] * p[0] + M[2] * p[1] + M[4], M[1] * p[0] + M[3] * p[1] + M[5]];+export function camFor(p, s, z, r = 0) {+ const dx = (s[0] - W / 2) / z, dy = (s[1] - H / 2) / z, co = Math.cos(-r), si = Math.sin(-r);+ return { x: p[0] - (co * dx - si * dy), y: p[1] - (si * dx + co * dy), z, r };+}+function viewBox(cam, pad = 0) { const r = Math.hypot(W, H) / 2 / cam.z + pad; return [cam.x - r, cam.y - r, cam.x + r, cam.y + r]; }++// ---------- textures ----------+function makeWeave(P) {+ const T = 64, cv = new OffscreenCanvas(T, T), g = cv.getContext('2d');+ g.fillStyle = P.bg; g.fillRect(0, 0, T, T);+ const h = T / 2;+ for (let by = 0; by < 2; by++) for (let bx = 0; bx < 2; bx++) {+ const horiz = (bx + by) % 2 === 0, x0 = bx * h, y0 = by * h;+ for (let i = 0; i < 7; i++) {+ const o = 3 + i * 4.2; g.strokeStyle = i % 2 ? P.weaveA : P.weaveA2; g.lineWidth = 2.2; g.beginPath();+ if (horiz) { g.moveTo(x0 + 1, y0 + o); g.lineTo(x0 + h - 1, y0 + o); } else { g.moveTo(x0 + o, y0 + 1); g.lineTo(x0 + o, y0 + h - 1); }+ g.stroke();+ }+ g.strokeStyle = P.weaveB; g.lineWidth = 1.2; g.strokeRect(x0 + 0.5, y0 + 0.5, h - 1, h - 1);+ }+ return cv;+}+function makeSpeckle(n, seed, rmin, rmax, T = 256) {+ const cv = new OffscreenCanvas(T, T), g = cv.getContext('2d');+ let s = seed; const rnd = () => (s = (s * 16807) % 2147483647) / 2147483647;+ g.fillStyle = '#000';+ for (let i = 0; i < n; i++) { const r = rmin + rnd() * (rmax - rmin); g.beginPath(); g.arc(rnd() * T, rnd() * T, r, 0, 6.2832); g.fill(); }+ return cv;+}+function makeMaskTex() { // solder mask: very soft mottling, so big pours aren't flat+ const T = 256, cv = new OffscreenCanvas(T, T), g = cv.getContext('2d');+ let s = 7; const rnd = () => (s = (s * 16807) % 2147483647) / 2147483647;+ for (let i = 0; i < 1400; i++) { const r = 3 + rnd() * 10; g.fillStyle = `rgba(${rnd() < 0.5 ? '255,255,255' : '0,0,0'},${0.006 + rnd() * 0.009})`; g.beginPath(); g.arc(rnd() * T, rnd() * T, r, 0, 6.2832); g.fill(); }+ return cv;+}+function octaves(base, z, target) { const s = Math.log(target / (base * z)) / Math.log(4), k = Math.floor(s); return [[base * Math.pow(4, k), 1], [base * Math.pow(4, k + 1), s - k]]; }++export class Board {+ constructor(canvas, world, opts = {}) {+ this.cv = canvas; this.ctx = canvas.getContext('2d'); this.w = world; this.o = opts;+ const mk = () => { const c = new OffscreenCanvas(W, H); return [c, c.getContext('2d')]; };+ [this.cuA, this.gA] = mk(); [this.cuB, this.gB] = mk(); [this.silk, this.sctx] = mk(); [this.glow, this.gctx] = mk();+ this.weave = makeWeave(PAL); this.pin = makeSpeckle(260, 11, 0.6, 1.6); this.mtex = makeMaskTex();+ this.u = opts.unit || 1; // a typical feature size (world units), used for LOD thresholds+ this.chans = [...(world.RIVER || []), ...(world.TAIL ? [world.TAIL] : [])].map(c => ({ ...c, m: measure(c.pts) }));+ this.pens = (world.PENS || []).map(c => ({ ...c, m: measure(c.pts) }));+ this.resFlow = (world.RES_FLOW || []).map(c => ({ ...c, m: measure(c.pts) }));+ for (const c of [...this.chans, ...this.pens, ...this.resFlow]) c.lines = [-0.34, -0.2, -0.07, 0.07, 0.2, 0.34].map(f => offset(c.pts, f * c.w));+ this.fence = world.fence ? world.fence() : [];+ this.stitch = world.stitch ? world.stitch() : [];+ }+ pattern(ctx, img, M, unit) { const pat = ctx.createPattern(img, 'repeat'), k = unit / img.width; pat.setTransform(new DOMMatrix([M[0] * k, M[1] * k, M[2] * k, M[3] * k, M[4], M[5]])); return pat; }+ boardPath(ctx, inset = 0) { const B = this.w.BOARD, i = inset; ctx.beginPath(); ctx.roundRect(B.x0 + i, B.y0 + i, B.x1 - B.x0 - 2 * i, B.y1 - B.y0 - 2 * i, Math.max(0.5, B.r - i)); }++ // copper pour minus every clearance, `e` = extra clearance (the rim pass uses e > 0)+ copper(g, M, vb, z, e, color) {+ const Wd = this.w, clr = (Wd.CLR ?? 4) + e;+ g.setTransform(1, 0, 0, 1, 0, 0); g.globalCompositeOperation = 'source-over'; g.clearRect(0, 0, W, H);+ g.setTransform(...M); g.fillStyle = color; this.boardPath(g, Wd.BOARD.inset + e); g.fill();+ g.globalCompositeOperation = 'destination-out'; g.fillStyle = '#000'; g.strokeStyle = '#000'; g.lineJoin = 'miter'; g.lineCap = 'butt'; g.miterLimit = 3;+ if (Wd.SEA) { poly(g, Wd.SEA); g.closePath(); g.lineWidth = 2 * e; g.fill(); if (e) g.stroke(); }+ for (const L of Wd.LAKES || []) { poly(g, L); g.closePath(); g.fill(); g.lineWidth = 2 * (clr * 0.6 + e); g.stroke(); }+ if (Wd.RESERVOIR) { poly(g, Wd.RESERVOIR); g.closePath(); g.fill(); g.lineWidth = 2 * (clr * 0.6 + e); g.stroke(); }+ for (const c of this.chans) { if (!inView(c, vb)) continue; g.lineWidth = c.w + 2 * (clr * 0.6 + e); poly(g, c.pts); g.stroke(); }+ for (const c of this.pens) { g.lineWidth = c.w + 2 * (clr * 0.45 + e); poly(g, c.pts); g.stroke(); }+ for (const c of Wd.STREETS || []) { g.lineWidth = c.w + 2 * (clr * 0.5 + e); poly(g, c.pts); g.stroke(); }+ for (const c of Wd.SLOTS || []) { g.lineCap = 'round'; g.lineWidth = c.w + 2 * (clr + e); poly(g, c.pts); g.stroke(); g.lineCap = 'butt'; }+ for (const h of Wd.HOLES_OVAL || []) { g.beginPath(); g.ellipse(h[0], h[1], 6 + clr + e, 13 + clr + e, 0, 0, 6.2832); g.fill(); }+ g.lineCap = 'round'; g.lineJoin = 'round';+ for (const t of Wd.TRACES) { if (t.layer === 'bottom' || !inView(t, vb)) continue; g.lineWidth = t.w + 2 * clr * (t.clrK ?? 1); poly(g, t.pts); g.stroke(); }+ for (const c of Wd.CLEARLINES || []) { g.lineWidth = c.w + 2 * e; g.lineJoin = 'miter'; poly(g, c.pts); g.stroke(); g.lineJoin = 'round'; }+ for (const p of Wd.PADS) padPath(g, p, clr * 0.8), g.fill();+ for (const k of Wd.KEEP || []) { keepPath(g, k, clr * 0.5 + e); g.fill(); }+ for (const v of Wd.VIAS || []) { circle(g, v[0], v[1], v[2] + clr * 0.6); g.fill(); }+ if (Wd.DAM) { const Dm = Wd.DAM; g.beginPath(); g.rect(Dm.x0 - clr, Dm.y0 - clr, Dm.x1 - Dm.x0 + 2 * clr, Dm.y1 - Dm.y0 + 2 * clr); g.fill(); }+ for (const h of Wd.HOLES || []) { circle(g, h[0], h[1], (Wd.HOLE_R || 30) * 1.45 + e); g.fill(); }+ for (const f of Wd.FIDS || []) { circle(g, f[0], f[1], (Wd.FID_R || 8) * 2.4 + e); g.fill(); }+ g.globalCompositeOperation = 'source-over';+ }++ // ---- main frame ----+ frame(cam, sc) {+ const { ctx } = this, P = PAL, M = camMatrix(cam), z = cam.z, vb = viewBox(cam, 60 / z), Wd = this.w, B = Wd.BOARD;+ ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.globalAlpha = 1; ctx.globalCompositeOperation = 'source-over'; ctx.filter = 'none';+ const bw = (B.x1 - B.x0) * 0.04;+ const edgeVisible = vb[0] < B.x0 + bw || vb[2] > B.x1 - bw || vb[1] < B.y0 + bw || vb[3] > B.y1 - bw;+ if (edgeVisible) {+ this.desk(ctx, cam, M, z, sc);+ ctx.save(); ctx.setTransform(...M); this.boardPath(ctx); ctx.restore(); ctx.save(); ctx.clip();+ } else ctx.save();++ // laminate (two weave octaves) + bottom-layer traces seen through it+ const u = this.u, [o1, o2] = octaves(u * 0.75, z, 11.1);+ ctx.fillStyle = this.pattern(ctx, this.weave, M, o1[0]); ctx.fillRect(0, 0, W, H);+ if (o2[1] > 0.01) { ctx.globalAlpha = o2[1]; ctx.fillStyle = this.pattern(ctx, this.weave, M, o2[0]); ctx.fillRect(0, 0, W, H); ctx.globalAlpha = 1; }+ ctx.setTransform(...M); ctx.lineCap = 'round'; ctx.lineJoin = 'round';+ for (const t of Wd.TRACES) if (t.layer === 'bottom') { poly(ctx, t.pts); ctx.strokeStyle = P.under; ctx.lineWidth = t.w; ctx.stroke(); }+ ctx.setTransform(1, 0, 0, 1, 0, 0);++ // copper pour: rim pass, then fill pass inset by the rim width+ const rim = 1.6 / z;+ this.copper(this.gA, M, vb, z, 0, P.pour.rim);+ this.copper(this.gB, M, vb, z, rim, P.pour.fill);+ { const g = this.gB; g.setTransform(1, 0, 0, 1, 0, 0); g.globalCompositeOperation = 'source-atop'; // mask mottling on the pour+ const [m1] = octaves(this.u * 9, z, 220); g.fillStyle = this.pattern(g, this.mtex, M, m1[0]); g.fillRect(0, 0, W, H); g.globalCompositeOperation = 'source-over'; }+ ctx.drawImage(this.cuA, 0, 0); ctx.drawImage(this.cuB, 0, 0);+ ctx.setTransform(...M);+ // via fences and stitching (on the pour)+ const fa = sstep(0.8, 2.2, (Wd.VIA_R || 2) * z);+ if (fa > 0.01) {+ ctx.globalAlpha = fa;+ const vr = (pts, r) => { for (const [x, y] of pts) { if (x < vb[0] || x > vb[2] || y < vb[1] || y > vb[3]) continue; circle(ctx, x, y, r); ctx.fillStyle = P.fence.ring; ctx.fill(); circle(ctx, x, y, r * 0.48); ctx.fillStyle = P.fence.hole; ctx.fill(); } };+ vr(this.stitch, Wd.VIA_R || 2); vr(this.fence, Wd.FENCE_R || Wd.VIA_R || 2);+ ctx.globalAlpha = 1;+ }+ // traces+ for (const t of Wd.TRACES) if (t.layer !== 'bottom' && inView(t, vb)) this.trace(ctx, t.pts, t.w, z);+ // exposed metal: the dam bar, pads, vias, holes+ if (Wd.DAM) this.damBar(ctx, z, sc);+ for (const p of Wd.PADS) this.pad(ctx, p, z, 0);+ for (const g of Wd.GENS || []) this.pad(ctx, g, z, sc.gens ? sc.gens[g.id] || 0 : 0);+ for (const v of Wd.VIAS || []) this.via(ctx, v, z);+ if (Wd.TPADS) this.tpads(ctx, z, vb, Wd.TPADS);+ for (const c of Wd.SLOTS || []) { poly(ctx, c.pts); ctx.lineCap = 'round'; ctx.lineWidth = c.w; ctx.strokeStyle = PAL.desk; ctx.stroke(); }+ for (const h of Wd.HOLES_OVAL || []) {+ ctx.beginPath(); ctx.ellipse(h[0], h[1], 6, 13, 0, 0, 6.2832); ctx.fillStyle = '#7A5A2A'; ctx.fill();+ const gr = ctx.createRadialGradient(h[0] - 1, h[1] - 3, 0.5, h[0], h[1], 12); gr.addColorStop(0, '#0B1A12'); gr.addColorStop(1, '#010302');+ ctx.beginPath(); ctx.ellipse(h[0], h[1], 4.8, 11.6, 0, 0, 6.2832); ctx.fillStyle = gr; ctx.fill();+ }+ for (const h of Wd.HOLES || []) this.hole(ctx, h, Wd.HOLE_R || 30, z);+ for (const f of Wd.FIDS || []) { circle(ctx, f[0], f[1], Wd.FID_R || 8); ctx.fillStyle = P.pad.fill; ctx.fill(); }++ // silkscreen+ this.silkLayer(M, z, sc, vb);+ ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.filter = 'blur(0.35px)'; ctx.drawImage(this.silk, 0, 0); ctx.filter = 'none';++ // light+ this.glowLayer(M, z, sc, vb);+ ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.globalCompositeOperation = 'lighter';+ ctx.filter = 'blur(24px)'; ctx.globalAlpha = 0.9; ctx.drawImage(this.glow, 0, 0);+ ctx.filter = 'blur(5px)'; ctx.globalAlpha = 0.85; ctx.drawImage(this.glow, 0, 0);+ ctx.filter = 'none'; ctx.globalAlpha = 1; ctx.drawImage(this.glow, 0, 0);+ ctx.globalCompositeOperation = 'source-over';+ if (Wd.DAM) { ctx.setTransform(...M); this.damBar(ctx, z, sc); ctx.setTransform(1, 0, 0, 1, 0, 0); } // the penstocks run under the dam+ if (sc.after) sc.after(ctx, M, z);+ ctx.restore();++ }++ desk(ctx, cam, M, z, sc) {+ ctx.fillStyle = PAL.desk; ctx.fillRect(0, 0, W, H);+ const dg = ctx.createRadialGradient(W / 2, H / 2, 0, W / 2, H / 2, W * 0.7);+ dg.addColorStop(0, PAL.deskHi); dg.addColorStop(1, 'rgba(0,0,0,0)'); ctx.fillStyle = dg; ctx.fillRect(0, 0, W, H);+ ctx.save(); ctx.setTransform(...M); ctx.filter = `blur(${Math.max(4, 22)}px)`;+ ctx.translate(14 / z, 22 / z); this.boardPath(ctx); ctx.fillStyle = 'rgba(0,0,0,0.7)'; ctx.fill(); ctx.restore(); ctx.filter = 'none';+ }+ windowLight(ctx, M, z, L) { // a parallelogram of noon light with a mullion shadow, in board space+ ctx.save(); ctx.setTransform(...M); ctx.globalCompositeOperation = 'soft-light';+ const q = L.quad; ctx.beginPath(); ctx.moveTo(...q[0]); for (const p of q.slice(1)) ctx.lineTo(...p); ctx.closePath();+ ctx.fillStyle = `rgba(255,236,196,${L.a})`; ctx.filter = `blur(${L.soft}px)`; ctx.fill(); ctx.restore();+ }++ trace(ctx, pts, w, z) {+ const P = PAL; poly(ctx, pts);+ if (w * z < 2.2) { ctx.strokeStyle = P.trace.rim; ctx.lineWidth = w; ctx.stroke(); return; }+ ctx.strokeStyle = P.trace.rim; ctx.lineWidth = w; ctx.stroke();+ ctx.strokeStyle = P.trace.fill; ctx.lineWidth = Math.max(w - 2.2 / z, w * 0.55); ctx.stroke();+ }+ pad(ctx, p, z, lit) {+ const P = PAL, st = P.pad;+ padPath(ctx, p, 0); ctx.fillStyle = st.fill; ctx.fill();+ ctx.lineWidth = Math.min(p.r ?? 1, 1.2 / z); ctx.strokeStyle = st.edge; ctx.stroke();+ ctx.save(); ctx.clip();+ const h = p.h ?? 2 * p.r, w_ = p.w ?? 2 * p.r;+ ctx.fillStyle = st.sheen; ctx.fillRect(p.x - w_ / 2, p.y - h / 2, w_, h * 0.34);+ if (lit > 0) { ctx.fillStyle = `rgba(255,236,170,${0.85 * lit})`; ctx.fillRect(p.x - w_, p.y - h, 2 * w_, 2 * h); }+ ctx.restore();+ if (p.hole) { circle(ctx, p.x, p.y, p.hole); ctx.fillStyle = st.hole; ctx.fill(); }+ }+ tpads(ctx, z, vb, list) {+ const P = PAL, small = 2.2 * z < 1.6;+ ctx.fillStyle = P.pad.fill;+ for (const p of list) {+ if (p.x < vb[0] || p.x > vb[2] || p.y < vb[1] || p.y > vb[3]) continue;+ if (small) { ctx.globalAlpha = 0.55; ctx.fillRect(p.x - p.w / 2, p.y - p.h / 2, p.w, p.h); ctx.globalAlpha = 1; continue; }+ if (p.r && p.w * z > 12) { ctx.beginPath(); ctx.roundRect(p.x - p.w / 2, p.y - p.h / 2, p.w, p.h, p.r); ctx.fill(); } else ctx.fillRect(p.x - p.w / 2, p.y - p.h / 2, p.w, p.h);+ }+ if (!small) { ctx.fillStyle = P.pad.sheen; for (const p of list) { if (p.x < vb[0] || p.x > vb[2] || p.y < vb[1] || p.y > vb[3]) continue; ctx.fillRect(p.x - p.w / 2, p.y - p.h / 2, p.w, p.h * 0.32); } }+ }+ via(ctx, v, z) { circle(ctx, v[0], v[1], v[2]); ctx.fillStyle = PAL.pad.fill; ctx.fill(); circle(ctx, v[0], v[1], v[3]); ctx.fillStyle = PAL.pad.hole; ctx.fill(); }+ hole(ctx, h, r, z) {+ circle(ctx, h[0], h[1], r * 1.25); ctx.fillStyle = PAL.pad.fill; ctx.fill();+ circle(ctx, h[0], h[1], r * 0.8); ctx.fillStyle = PAL.desk; ctx.fill();+ }+ damBar(ctx, z, sc) {+ const Dm = this.w.DAM, P = PAL;+ const g = ctx.createLinearGradient(0, Dm.y0, 0, Dm.y1);+ g.addColorStop(0, P.copper.hi); g.addColorStop(0.35, P.copper.mid); g.addColorStop(1, P.copper.lo);+ ctx.beginPath(); ctx.rect(Dm.x0, Dm.y0, Dm.x1 - Dm.x0, Dm.y1 - Dm.y0); ctx.fillStyle = g; ctx.fill();+ ctx.lineWidth = 1 / z; ctx.strokeStyle = P.copper.edge; ctx.stroke();+ // brushed streaks+ ctx.save(); ctx.clip(); ctx.globalAlpha = 0.18; ctx.strokeStyle = '#fff1dc'; ctx.lineWidth = 0.6 / z;+ for (let i = 0; i < 40; i++) { const y = Dm.y0 + (Dm.y1 - Dm.y0) * ((i * 0.618) % 1); ctx.beginPath(); ctx.moveTo(Dm.x0, y); ctx.lineTo(Dm.x1, y); ctx.stroke(); }+ ctx.restore();+ }++ silkLayer(M, z, sc, vb) {+ const g = this.sctx, Wd = this.w, P = PAL;+ g.setTransform(1, 0, 0, 1, 0, 0); g.clearRect(0, 0, W, H); g.setTransform(...M);+ g.strokeStyle = P.silk; g.fillStyle = P.silk; g.lineCap = 'round'; g.lineJoin = 'round';+ const prog = id => id ? (sc.labels?.[id] ?? 0) : 1;+ for (const s of Wd.SILK || []) {+ const pr = prog(s.plot); if (pr <= 0) continue;+ if (s.w * z < 0.25) continue;+ g.globalAlpha = sstep(0.25, 0.7, s.w * z);+ g.lineWidth = s.w;+ if (s.circle) { g.beginPath(); g.arc(s.circle[0], s.circle[1], s.circle[2], 0, 6.2832 * pr); g.stroke(); continue; }+ if (s.tilde) { const [x, y] = s.tilde, k = s.s; g.beginPath(); g.moveTo(x, y + k * 0.25); g.lineTo(x + k * 0.25, y); g.lineTo(x + k * 0.5, y + k * 0.25); g.lineTo(x + k * 0.75, y + k * 0.5); g.lineTo(x + k, y + k * 0.25); g.stroke(); continue; }+ if (s.dash) g.setLineDash(s.dash);+ const pts = pr < 1 ? sub(measureCache(s), 0, measureCache(s).len * pr) : s.pts;+ if (pts.length > 1) { poly(g, pts); if (s.fill) { g.closePath(); g.fill(); } else g.stroke(); }+ if (s.dash) g.setLineDash([]);+ }+ g.globalAlpha = 1;+ // board furniture+ if (Wd.HOLES) for (const h of Wd.HOLES) { g.lineWidth = (Wd.HOLE_R || 30) * 0.12; g.beginPath(); g.arc(h[0], h[1], (Wd.HOLE_R || 30) * 1.55, 0, 6.2832); g.stroke(); }+ if (Wd.TITLE && (sc.labels?.titleBox ?? 0) > 0) this.titleBlock(g, Wd.TITLE, sc.labels.titleBox);+ // designators: fade when too small+ for (const d of this.o.noDesig ? [] : Wd.DESIG || []) { const a = sstep(5, 9, d.cap * z); if (a < 0.01) continue; g.globalAlpha = a; drawText(g, d.text, d.x, d.y, d.cap, { align: d.align, weight: 0.16 }); }+ g.globalAlpha = 1;+ // labels, plotted stroke by stroke+ for (const L of Wd.LABELS || []) {+ const pr = sc.labels?.[L.id] ?? 0; if (pr <= 0) continue;+ if (L.cap * z < 2) continue;+ g.strokeStyle = P.silk;+ drawText(g, L.text, L.x, L.y, L.cap, { align: L.align, sw: L.sw, progress: pr });+ if (L.tag) { g.lineWidth = L.tag.w; const fr = L.tag.frame, m = measureCache({ pts: fr }); const pts = sub(m, 0, m.len * Math.min(1, pr * 1.3)); if (pts.length > 1) { poly(g, pts); g.stroke(); } }+ }+ // print texture: pinholes+ g.setTransform(1, 0, 0, 1, 0, 0); g.globalCompositeOperation = 'destination-out';+ const [p1, p2] = octaves(this.u * 3, z, 89);+ g.globalAlpha = 1 - p2[1]; g.fillStyle = this.pattern(g, this.pin, M, p1[0]); g.fillRect(0, 0, W, H);+ g.globalAlpha = p2[1]; g.fillStyle = this.pattern(g, this.pin, M, p2[0]); g.fillRect(0, 0, W, H);+ g.globalAlpha = 1; g.globalCompositeOperation = 'source-over';+ }+ titleBlock(g, T, pr) { g.lineWidth = T.h * 0.03; g.strokeRect(T.x, T.y, T.w * pr, T.h); }++ glowLayer(M, z, sc, vb) {+ const g = this.gctx, P = PAL;+ g.setTransform(1, 0, 0, 1, 0, 0); g.clearRect(0, 0, W, H); g.setTransform(...M);+ g.lineCap = 'round'; g.lineJoin = 'round'; g.globalCompositeOperation = 'lighter';+ const t = sc.t || 0;+ // ---- water (silver) ----+ if (sc.water) {+ const wa = sc.water;+ if (wa.res > 0 && this.w.RESERVOIR) { poly(g, this.w.RESERVOIR); g.closePath(); g.fillStyle = rgb(P.water.g, 0.07 * wa.res); g.fill(); }+ for (const c of this.chans) { const a = (c.id === 'tail' ? wa.tail : c.id === 'jinsha' ? wa.up : wa.river) ?? wa.river; if (a > 0 && inView(c, vb)) this.flow(g, c, z, t, a, 1); }+ if (wa.res > 0) for (const c of this.resFlow) this.flow(g, c, z, t, wa.res, 0.55);+ for (const c of this.pens) { const p = wa.pen?.[c.id] ?? 0; if (p > 0) this.penFlow(g, c, z, t, p, wa.penA ?? 1); }+ }+ // ---- current (amber) ----+ for (const a of sc.ac || []) this.acDashes(g, a, z, t);+ for (const d of sc.dc || []) this.dcStream(g, d, z, t);+ if (sc.lit && this.w.TPADS) {+ const c = P.cur.g; g.fillStyle = rgb(c, 0.55 * sc.lit);+ for (const p of this.w.TPADS) if (p.lit && (!sc.litOnly || sc.litOnly(p)) && p.x > vb[0] && p.x < vb[2] && p.y > vb[1] && p.y < vb[3]) g.fillRect(p.x - p.w * 0.42, p.y - p.h * 0.42, p.w * 0.84, p.h * 0.84);+ }+ for (const p of sc.glow || []) { poly(g, p.pts); g.strokeStyle = rgb(p.c || P.cur.g, p.a); g.lineWidth = p.w; g.stroke(); }+ for (const f of sc.flashes || []) {+ const R = Math.min(f.r, (f.maxPx || 150) / z), rg = g.createRadialGradient(f.p[0], f.p[1], 0, f.p[0], f.p[1], R);+ const c = f.c || P.cur; rg.addColorStop(0, rgb(c.h, f.a)); rg.addColorStop(1, rgb(c.g, 0)); g.fillStyle = rg; g.beginPath(); g.arc(f.p[0], f.p[1], R, 0, 6.2832); g.fill();+ }+ g.globalCompositeOperation = 'source-over';+ }+ // silver flow light: streamlines of moving dashes, each its own speed and rhythm+ flow(g, c, z, t, a, k) {+ const P = PAL, w = c.w;+ poly(g, c.pts); g.strokeStyle = rgb(P.water.g, (0.1 + 0.26 * (1 - clamp(w * z / 40))) * a); g.lineWidth = w * 0.9; g.stroke();+ const n = c.lines.length;+ for (let i = 0; i < n; i++) {+ const f = (i / (n - 1)) * 2 - 1, v = w * (5.2 - 2.6 * f * f) * k, dl = w * (0.9 + 0.7 * ((i * 0.37) % 1)), gp = w * (1.3 + 1.6 * ((i * 0.61) % 1));+ g.setLineDash([dl, gp]); g.lineDashOffset = -(t * v + i * w * 0.83);+ poly(g, c.lines[i]); g.strokeStyle = rgb(P.water.g, (0.5 - 0.2 * Math.abs(f)) * a); g.lineWidth = Math.max(w * 0.06, 0.9 / z); g.stroke();+ // ripples: short glints riding faster+ g.setLineDash([w * 0.18, w * (2.6 + 1.3 * ((i * 0.29) % 1))]); g.lineDashOffset = -(t * v * 1.35 + i * w * 1.7);+ g.strokeStyle = rgb(P.water.h, 0.42 * a); g.lineWidth = Math.max(w * 0.045, 0.8 / z); g.stroke();+ }+ g.setLineDash([]);+ }+ penFlow(g, c, z, t, p, a) {+ const P = PAL, m = c.m, w = c.w, s = m.len * Math.min(1, p);+ const pts = sub(m, 0, s); if (pts.length < 2) return;+ poly(g, pts); g.strokeStyle = rgb(P.water.g, 0.16 * a); g.lineWidth = w * 0.8; g.stroke();+ g.setLineDash([w * 2.6, w * 3.4]); g.lineDashOffset = -(t * w * 7 + c.k * w * 1.9);+ g.strokeStyle = rgb(P.water.h, 0.42 * a); g.lineWidth = w * 0.22; g.stroke(); g.setLineDash([]);+ if (p < 1.02) { const h = at(m, s), R = w * 1.6; const rg = g.createRadialGradient(h[0], h[1], 0, h[0], h[1], R); rg.addColorStop(0, `rgba(255,255,255,${0.95 * a})`); rg.addColorStop(1, rgb(P.water.g, 0)); g.fillStyle = rg; g.beginPath(); g.arc(h[0], h[1], R, 0, 6.2832); g.fill(); }+ }+ // AC: short dashes that rock back and forth along the trace (a slowed 50 Hz), over a faint energised line+ acDashes(g, a, z, t) {+ const P = PAL, tr = a.trace, m = tr.m, s0 = a.s0 ?? 0, s1 = Math.min(m.len, a.s1 ?? m.len); if (s1 <= s0) return;+ const pts = sub(m, s0, s1); if (pts.length < 2) return;+ if (a.fade) return this.lossDashes(g, a, z, t, pts, s0, s1);+ const lam = a.lam || tr.w * 4, A = lam * (a.amp ?? 0.32), ph = Math.sin(a.phase ?? (2 * Math.PI * (a.f ?? 2.2) * t + (a.ph || 0))) * A;+ poly(g, pts); g.strokeStyle = rgb(P.cur.e, 0.12 * a.a); g.lineWidth = tr.w * 0.45; g.stroke();+ g.lineCap = 'round'; g.setLineDash([lam * 0.36, lam * 0.64]); g.lineDashOffset = -(ph + (a.drift || 0) * t) + lam * 0.3;+ poly(g, pts); g.strokeStyle = rgb(P.cur.g, 0.85 * a.a); g.lineWidth = tr.w * 0.8; g.stroke();+ g.strokeStyle = `rgba(255,240,205,${0.45 * a.a})`; g.lineWidth = tr.w * 0.22; g.stroke();+ g.setLineDash([]); g.lineDashOffset = 0;+ }+ // AC sent too far: dashes moving forward, dimmer, thinner and fewer the further they get+ lossDashes(g, a, z, t, pts, s0, s1) {+ const P = PAL, tr = a.trace, m = tr.m, lam = a.lam || tr.w * 5, w = tr.w, off = ((t * (a.v || lam * 1.2)) % lam + lam) % lam;+ poly(g, pts); g.strokeStyle = rgb(P.cur.e, 0.1 * a.a); g.lineWidth = w * 0.45; g.stroke();+ g.lineCap = 'round';+ for (let s = s0 + off - lam, k = Math.floor((t * (a.v || lam * 1.2)) / lam); s < s1; s += lam, k--) {+ const d = s - (a.x0 ?? s0); if (d < 0) continue;+ const keep = Math.exp(-d / (a.fade * 1.4)), h = Math.abs(Math.sin(k * 12.9898) * 43758.5453) % 1;+ if (h > keep + 0.12) continue;+ const k2 = Math.exp(-d / a.fade) * a.a, L = lam * 0.38 * (0.45 + 0.55 * Math.exp(-d / a.fade));+ const q = sub(m, Math.max(s0, s), Math.min(s1, s + L)); if (q.length < 2) continue;+ poly(g, q); g.strokeStyle = rgb(P.cur.g, Math.min(1, 1.1 * k2)); g.lineWidth = w * (0.45 + 0.6 * Math.exp(-d / a.fade)); g.stroke();+ g.strokeStyle = `rgba(255,240,205,${0.6 * k2})`; g.lineWidth = w * 0.2; g.stroke();+ }+ }+ // DC: one direction, continuous: a lit stream behind a travelling head, with a slow afterglow and fast streaks+ dcStream(g, d, z, t) {+ const P = PAL, tr = d.trace, m = tr.m, head = Math.min(m.len, d.head ?? m.len), s0 = d.s0 ?? 0, w = tr.w, a = d.a ?? 1;+ if (head <= s0) return;+ const decay = d.decay ?? 1e9, N = 28;+ for (let i = 0; i < N; i++) {+ const sA = s0 + (head - s0) * i / N, sB = s0 + (head - s0) * (i + 1) / N, mid = (sA + sB) / 2;+ const k = Math.max(d.floor ?? 0.35, Math.exp(-(head - mid) / decay)) * a;+ const pts = sub(m, sA, sB + 0.01); if (pts.length < 2) continue;+ g.lineCap = 'butt'; poly(g, pts); g.strokeStyle = rgb(P.cur.g, 0.6 * k); g.lineWidth = Math.max(w * 0.9, (d.minPx || 3.6) / z); g.stroke();+ g.strokeStyle = `rgba(255,244,214,${0.38 * k})`; g.lineWidth = Math.max(w * 0.3, (d.minPx || 3.6) * 0.4 / z); g.stroke();+ }+ // streaks travelling with the current+ const pts = sub(m, s0, head);+ if (pts.length > 1) { g.setLineDash([w * 6, w * 9]); g.lineDashOffset = -(t * (d.v || w * 40)); poly(g, pts); g.strokeStyle = `rgba(255,252,240,${0.35 * a})`; g.lineWidth = w * 0.3; g.stroke(); g.setLineDash([]); }+ g.lineCap = 'round';+ if (d.headGlow !== false && head < m.len - 0.01) {+ const h = at(m, head), R = Math.min(w * 3.2, (d.maxPx || 70) / z);+ const rg = g.createRadialGradient(h[0], h[1], 0, h[0], h[1], R); rg.addColorStop(0, `rgba(255,255,255,${a})`); rg.addColorStop(0.4, rgb(P.cur.h, 0.85 * a)); rg.addColorStop(1, rgb(P.cur.g, 0));+ g.fillStyle = rg; g.beginPath(); g.arc(h[0], h[1], R, 0, 6.2832); g.fill();+ }+ }++ // every label visible at this camera, as screen boxes (for readcheck)+ texts(cam, sc, prefix = '') {+ const M = camMatrix(cam), out = [];+ for (const L of this.w.LABELS || []) {+ if ((sc.labels?.[L.id] ?? 0) <= 0) continue;+ const wd = layout(L.text).width * L.cap / 10;+ const x0 = L.align === 'center' ? L.x - wd / 2 : L.align === 'right' ? L.x - wd : L.x;+ const cs = [[x0, L.y - L.cap * 0.1], [x0 + wd, L.y - L.cap * 0.1], [x0, L.y + L.cap * 1.1], [x0 + wd, L.y + L.cap * 1.1]].map(p => toScreen(M, p));+ const xs = cs.map(p => p[0]), ys = cs.map(p => p[1]);+ if (Math.max(...ys) - Math.min(...ys) < 9) continue; // too small to read: texture, not text+ out.push({ id: L.gid || prefix + L.id, text: L.text, x0: Math.min(...xs), y0: Math.min(...ys), x1: Math.max(...xs), y1: Math.max(...ys) });+ }+ return out;+ }+}++const mc = new WeakMap();+function measureCache(ld) { if (!mc.has(ld)) mc.set(ld, measure(ld.pts)); return mc.get(ld); }+function inView(t, vb) {+ if (!t.bb) { let x0 = 1e9, y0 = 1e9, x1 = -1e9, y1 = -1e9; for (const [x, y] of t.pts) { x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x); y1 = Math.max(y1, y); } const p = (t.w || 0) + 20; t.bb = [x0 - p, y0 - p, x1 + p, y1 + p]; }+ const b = t.bb; return !(b[2] < vb[0] || b[0] > vb[2] || b[3] < vb[1] || b[1] > vb[3]);+}+function padPath(ctx, p, e) {+ ctx.beginPath();+ if (p.shape === 'round') ctx.arc(p.x, p.y, p.r + e, 0, 6.2832);+ else if (p.shape === 'square') ctx.rect(p.x - p.r - e, p.y - p.r - e, 2 * (p.r + e), 2 * (p.r + e));+ else ctx.roundRect(p.x - p.w / 2 - e, p.y - p.h / 2 - e, p.w + 2 * e, p.h + 2 * e, (p.r || 0) + e);+}+function keepPath(ctx, k, e) {+ ctx.beginPath();+ if (k.rect) { const [x0, y0, x1, y1] = k.rect; ctx.rect(x0 - e, y0 - e, x1 - x0 + 2 * e, y1 - y0 + 2 * e); }+ else if (k.circle) ctx.arc(k.circle[0], k.circle[1], k.circle[2] + e, 0, 6.2832);+ else if (k.poly) { const c = k.poly.reduce((s, p) => [s[0] + p[0] / k.poly.length, s[1] + p[1] / k.poly.length], [0, 0]); k.poly.forEach((p, i) => { const dx = p[0] - c[0], dy = p[1] - c[1], L = Math.hypot(dx, dy) || 1, q = [p[0] + dx / L * e * 1.41, p[1] + dy / L * e * 1.41]; i ? ctx.lineTo(...q) : ctx.moveTo(...q); }); ctx.closePath(); }+}+export function poly(ctx, pts) { ctx.beginPath(); ctx.moveTo(pts[0][0], pts[0][1]); for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i][0], pts[i][1]); }+export function circle(ctx, x, y, r) { ctx.beginPath(); ctx.arc(x, y, r, 0, 6.2832); }diff --git a/styles/circuit-board/demo/src/world.js b/styles/circuit-board/demo/src/world.jsnew file mode 100644index 0000000..9901bca--- /dev/null+++ b/styles/circuit-board/demo/src/world.js@@ -0,0 +1,347 @@+// The corridor board: the Yangtze corridor from Baihetan to the river mouth, 1 unit ≈ 1 km.+// Only real things are drawn: the river (a bare channel in the copper), four lakes, the coast at the east end,+// the dam and its 16 units, the two converter stations, the ±800 kV pair, test pads every 500 km.+// Everything the film shows on this board lives here, so the closing pull-out shows the same silkscreen.+import { P, octi, offset, measure, at, sub, frameAt } from './geo.js';+import { textWidth } from './font.js';+import { bridge, ground, tag, box, xformer, reactor, capBank, chamferBox } from './parts.js';++export const BOARD = { x0: -60, y0: -90, x1: 2140, y1: 1010, r: 36, inset: 14 };+const LL = pts => pts.map(p => (typeof p[0] === 'number' && p.length >= 2 && Math.abs(p[0]) < 200 && Math.abs(p[1]) < 90 && p[0] > 90) ? [...P(p[0], p[1]), p[2]] : p);++// ---------- Baihetan: the dam complex (local units scaled by DS around D) ----------+export const D = P(102.9, 27.21);+export const DS = 1.5;+const d = (x, y) => [D[0] + x * DS, D[1] + y * DS];+export const PEN_N = 8, PEN_PITCH = 6, PAD_Y = 12, BUS_Y = 20;+const padX = k => 36 + PEN_PITCH * k; // local x of generator k on the right bank+// penstocks: from the reservoir wall, across under the dam, to each generator (s = -1 left bank, +1 right bank)+export const PENS = [];+for (const s of [1, -1]) for (let k = 0; k < PEN_N; k++) {+ const yk = -6 - PEN_PITCH * k;+ PENS.push({ id: `pen${s > 0 ? 'R' : 'L'}${k}`, s, k, pts: [d(s * 10, yk), d(s * 16, yk), d(s * padX(k), PAD_Y - 2.9)], w: 1.7 * DS });+}+// generators: right bank G1..G8 (to Jiangsu), left bank G9..G16 (to Zhejiang)+export const GENS = [];+for (const s of [1, -1]) for (let k = 0; k < PEN_N; k++) {+ const [x, y] = d(s * padX(k), PAD_Y);+ GENS.push({ id: `G${s > 0 ? 1 + k : 9 + k}`, s, k, x, y, w: 4.4 * DS, h: 5.4 * DS, shape: 'rect', r: 0.7 * DS });+}+export const DAM = { x0: d(-74, 0)[0], x1: d(74, 0)[0], y0: d(0, -2.6)[1], y1: d(0, 2.6)[1] };+// reservoir (a widening of the channel above the dam)+export const RESERVOIR = [d(-2.4, -92), d(2.4, -92), d(10, -84.4), d(10, -2.6), d(-10, -2.6), d(-10, -84.4)];+// generator leads into the two bus bars+export const LEADS = GENS.map(g => ({ id: 'lead' + g.id, pts: [[g.x, g.y + g.h / 2], [g.x, d(0, BUS_Y)[1]]], w: 1.2 * DS, net: 'ac' }));++// ---------- Butuo converter (AC -> DC) ----------+export const BR = 7;+export const BUTUO = bridge(d(126, -96), BR, { id: 'butuo', sw: 0.42 });+// ---------- Yucheng converter (DC -> AC), the mirror ----------+export const YC = P(120.75, 31.65);+export const YUCHENG = bridge(YC, BR, { id: 'yucheng', sw: 0.42 });++// ---------- the river ----------+const up = octi([[62.4, -111], [62.4, 255], [124.8, 327, 'd'], [124.8, 560], [220.8, 656, 'd'], d(0, -88)]);+const yz = LL([+ d(0, 0), d(0, 40), [...d(12, 52), 'd'], [420, d(0, 52)[1]], [554, d(0, 52)[1] - 134, 'd'], [554, 560], [106.58, 29.56, 's'],+ [107.39, 29.71, 'd'], [108.04, 30.30, 's'], [108.41, 30.81, 'd'], [109.47, 31.02, 's'], [110.34, 31.04, 'd'], [111.29, 30.70, 's'], [111.76, 30.42, 'd'],+ [112.24, 30.30, 's'], [112.95, 29.55, 'd'], [113.55, 29.62, 's'], [114.30, 30.45, 'd'], [114.85, 30.40, 's'], [115.55, 29.80, 'd'], [116.10, 29.75, 's'], [117.05, 30.52, 'd'], [117.82, 30.95, 's'], [118.38, 31.33, 'd'], [118.50, 31.70, 's'], [118.78, 32.07, 'd'],+ [119.45, 32.21, 's'], [120.28, 31.92, 'd'], [120.86, 32.00, 's'], [121.40, 31.72, 'd'], [122.6, 31.45, 's'],+]);+const main = octi(yz);+// tributaries (narrower channels): Jialing, Wu, Han, Xiang, Gan+const trib = pts => octi(LL(pts));+export const RIVER = [+ { id: 'jinsha', pts: up, w: 7, kind: 'river' },+ { id: 'yangtze', pts: main, w: 12, kind: 'river' },+ { id: 'jialing', pts: trib([[106.05, 35.3], [106.05, 32.4], [106.3, 31.0, 'd'], [106.3, 30.2, 's'], [106.58, 29.62, 'd']]), w: 5, kind: 'river' },+ { id: 'wu', pts: trib([[107.2, 25.0], [107.2, 27.6], [107.6, 28.4, 'd'], [107.6, 29.0, 's'], [107.39, 29.68, 'd']]), w: 5, kind: 'river' },+ { id: 'han', pts: trib([[109.6, 35.3], [109.6, 33.0], [111.2, 32.6, 'd'], [112.2, 31.7, 'd'], [112.6, 30.9, 's'], [113.6, 30.65, 'd'], [114.25, 30.56, 's']]), w: 5, kind: 'river' },+ { id: 'xiang', pts: trib([[112.6, 25.0], [112.6, 27.2], [112.95, 27.9, 'd'], [112.95, 29.0, 's']]), w: 5, kind: 'river' },+ { id: 'gan', pts: trib([[115.6, 25.0], [115.6, 27.6], [115.9, 28.2, 'd'], [116.3, 28.9, 'd']]), w: 5, kind: 'river' },+ { id: 'hukou', pts: trib([[116.2, 29.4], [116.2, 29.78]]), w: 6, kind: 'river' },+];+// the tailrace below the dam is wider+export const TAIL = { id: 'tail', pts: [d(0, 5.5), d(0, 40), d(12, 52), [d(12, 52)[0] + 30, d(0, 52)[1]]], w: 15, kind: 'river' };++// ---------- lakes and the sea (no copper) ----------+const lake = pts => octi([...LL(pts), LL([pts[0]])[0]]);+export const LAKES = [+ lake([[112.35, 29.45], [112.85, 29.55, 'd'], [113.1, 29.35, 's'], [113.0, 28.95, 'd'], [112.6, 28.8, 's'], [112.3, 29.0, 'd']]), // Dongting+ lake([[115.95, 29.6], [116.35, 29.45, 'd'], [116.7, 29.05, 's'], [116.55, 28.7, 'd'], [116.2, 28.8, 's'], [116.05, 29.2, 'd']]), // Poyang+ lake([[117.3, 31.65], [117.7, 31.7, 's'], [117.85, 31.55, 'd'], [117.55, 31.45, 's'], [117.3, 31.5, 'd']]), // Chaohu+ lake([[119.95, 31.5], [120.45, 31.5, 's'], [120.6, 31.2, 'd'], [120.4, 30.95, 's'], [120.0, 31.0, 'd'], [119.9, 31.2, 's']]), // Taihu+];+const coast = octi(LL([[119.3, 35.3], [119.3, 34.6], [120.2, 34.3, 'd'], [120.5, 33.6, 's'], [120.8, 32.8, 'd'], [121.3, 32.4, 'd'], [121.95, 31.75, 'd'],+ [121.95, 31.2, 's'], [121.85, 30.9, 'd'], [121.1, 30.65, 's'], [120.6, 30.4, 'd'], [121.1, 30.2, 'd'], [121.7, 29.95, 's'], [121.95, 29.6, 'd'],+ [121.6, 28.9, 's'], [121.4, 28.2, 'd'], [120.9, 27.6, 's'], [120.4, 26.8, 'd'], [119.9, 26.1, 's'], [119.6, 24.6, 'd']]));+export const SEA = [...coast, [BOARD.x1 + 50, coast[coast.length - 1][1]], [BOARD.x1 + 50, coast[0][1]]];++// ---------- the ±800 kV pair ----------+const B0 = BUTUO.c, Y0 = YUCHENG.c;+export const LINE_C = octi([+ [B0[0] + 58, B0[1]], [600, B0[1]], [666, 566, 'd'], [778, 566], [878, 466, 'd'], [960, 466], [1087.5, 338.5, 'd'], [1632, 338.5], [1687.5, 283, 'd'], [Y0[0] - 58, Y0[1]],+]);+export const PAIR = 3.0; // half the pitch of the pair in the corridor+const plus = offset(LINE_C, PAIR), minus = offset(LINE_C, -PAIR);+const bT = BUTUO.T, bB = BUTUO.B, yT = YUCHENG.T, yB = YUCHENG.B;+const leadIn = (V, s, p0) => { const dy = p0[1] - V[1]; return [V, [p0[0] - Math.abs(dy), V[1]], p0]; };+const leadOut = (V, s, p1) => { const dy = p1[1] - V[1]; return [p1, [p1[0] + Math.abs(dy), V[1]], V]; };+export const DCP = { id: 'dcp', pts: dedupe([...leadIn(bT, -1, plus[0]), ...plus.slice(1, -1), ...leadOut(yT, -1, plus[plus.length - 1])]), w: 1.8, net: 'dc' };+export const DCN = { id: 'dcn', pts: dedupe([...leadIn(bB, 1, minus[0]), ...minus.slice(1, -1), ...leadOut(yB, 1, minus[minus.length - 1])]), w: 1.8, net: 'dc' };+function dedupe(p) { const o = [p[0]]; for (let i = 1; i < p.length; i++) if (Math.hypot(p[i][0] - o[o.length - 1][0], p[i][1] - o[o.length - 1][1]) > 0.01) o.push(p[i]); return o; }++// ---------- AC buses ----------+const BUSR = [d(padX(0) - 2.2, BUS_Y), d(96, BUS_Y), d(96, -96), [BUTUO.L[0] - 20, BUTUO.L[1]]];+const BUSL = [d(-padX(0) + 2.2, BUS_Y), d(-92, BUS_Y), d(-92, 31)];+export const ACR = { id: 'acR', pts: BUSR, w: 1.8, net: 'ac' };+export const ACL = { id: 'acL', pts: BUSL, w: 1.8, net: 'ac' };+export const BARR = { id: 'barR', pts: [d(padX(0) - 2.2, BUS_Y), d(padX(7) + 2.2, BUS_Y)], w: 2.2 * DS, net: 'ac' };+export const BARL = { id: 'barL', pts: [d(-padX(0) + 2.2, BUS_Y), d(-padX(7) - 2.2, BUS_Y)], w: 2.2 * DS, net: 'ac' };+// AC out of Yucheng (towards the city)+export const CITY_AT = [1976, 306], CITY_S = 0.01, CITY_W = 1200, CITY_H = 800; // the city module (a child board)+export const T21 = xformer([YUCHENG.R[0] + 8.5, YUCHENG.R[1]], 6, [5, 6], 0.24); // converter transformer+export const T1 = xformer([YUCHENG.R[0] + 25, YUCHENG.R[1]], 4, [6, 4], 0.17);+export const stepLabel = (T) => [{ id: 'step', gid: 'step', text: '降压', x: T.c[0], y: T.c[1] - T.s * 1.02, cap: T.s * 0.17, sw: T.s * 0.017, align: 'center' }, { id: 'stepE', gid: 'stepE', text: 'STEP DOWN', x: T.c[0], y: T.c[1] - T.s * 0.76, cap: T.s * 0.08, sw: T.s * 0.012, align: 'center' }]; // regional 500 kV -> 220 kV+const cityIn = [CITY_AT[0], CITY_AT[1] + 120 * CITY_S];+export const ACY = { id: 'acY', pts: [YUCHENG.R, T21.inP], w: 1.4, net: 'ac' };+export const ACY2 = { id: 'acY2', pts: [T21.outP, T1.inP], w: 1.4, net: 'ac' };+export const ACY3 = { id: 'acY3', pts: [T1.outP, [1973.2, T1.outP[1]], [1973.2, cityIn[1]], cityIn], w: 0.7, net: 'ac' };+// station equipment: converter transformers on the AC side, AC filter banks, smoothing reactors on both poles+export const T11 = xformer([BUTUO.L[0] - 17, BUTUO.L[1]], 6, [6, 5], 0.24);+export const FILT_B = capBank(BUTUO.L[0] - 36.5, BUTUO.L[1], 4, 3.4, 3.2, 0.2, 1);+export const FILT_Y = capBank(YUCHENG.R[0] + 13.6, YUCHENG.R[1], 3, 3.0, 3.2, 0.2, -1);+export const REACT = [+ reactor([BUTUO.T[0] + 37, BUTUO.T[1]], 7, 0.24, -1), reactor([BUTUO.B[0] + 37, BUTUO.B[1]], 7, 0.24, 1),+ reactor([YUCHENG.T[0] - 37, YUCHENG.T[1]], 7, 0.24, -1), reactor([YUCHENG.B[0] - 37, YUCHENG.B[1]], 7, 0.24, 1),+];+// the returns: Butuo's right vertex and Yucheng's left vertex go to earth through a via+export const VIAS = [];+const viaB = [BUTUO.R[0] + 3.2, BUTUO.R[1]], viaY = [YUCHENG.L[0] - 3.2, YUCHENG.L[1]];+VIAS.push([...viaB, 1.3, 0.6], [...viaY, 1.3, 0.6]);+export const RET = [{ id: 'retB', pts: [BUTUO.R, viaB], w: 1.4, net: 'ret' }, { id: 'retY', pts: [YUCHENG.L, viaY], w: 1.4, net: 'ret' }];++// ---------- J2: the connector the left bank leaves the board through ----------+const J2 = d(-92, 36);+export const J2PADS = [0, 1, 2, 3].map(i => ({ x: J2[0] - 2.25 * DS + (i % 2) * 4.5 * DS, y: J2[1] + Math.floor(i / 2) * 4.5 * DS, r: 1.5 * DS, shape: i ? 'round' : 'square', hole: 0.7 * DS, id: 'J2:' + i }));++export const ACB2 = { id: 'acB2', pts: [T11.outP, BUTUO.L], w: 1.8, net: 'ac' };+const bankTr = (b, id) => b.traces.map((p, i) => ({ id: id + i, pts: p, w: 0.7, net: 'gnd' }));+export const TRACES = [ACR, ACB2, ACL, BARR, BARL, ...LEADS, DCP, DCN, ACY, ACY2, ACY3, ...RET, ...bankTr(FILT_B, 'fb'), ...bankTr(FILT_Y, 'fy')].map(t => ({ ...t, m: measure(t.pts) }));+export const byId = id => TRACES.find(t => t.id === id);+export const LINE_M = measure(LINE_C);+export const CLEARLINES = [{ pts: LINE_C, w: 2 * PAIR }];++// ---------- test pads every 500 km ----------+export const TPS = [500, 1000, 1500].map((km, i) => {+ const f = frameAt(LINE_M, LINE_M.len * km / 2080), q = [f.p[0] + f.n[0] * (PAIR + 9), f.p[1] + f.n[1] * (PAIR + 9)];+ const onPlus = [f.p[0] + f.n[0] * PAIR, f.p[1] + f.n[1] * PAIR];+ return { km, p: q, stub: [onPlus, q], s: LINE_M.len * km / 2080, text: `${km.toLocaleString('en-US')} km` };+});++// ---------- silkscreen ----------+const CN = 44, EN = 20, SWN = 3.2; // place names: Chinese line over an English line, one stroke width+function lineY(x) { for (let i = 1; i < LINE_C.length; i++) { const a = LINE_C[i - 1], b = LINE_C[i]; if ((a[0] - x) * (b[0] - x) <= 0 && a[0] !== b[0]) return a[1] + (b[1] - a[1]) * (x - a[0]) / (b[0] - a[0]); } return LINE_C[0][1]; }+const name = (id, cn, en, lon, gap) => {+ const x = P(lon, 0)[0], y = gap > 0 ? lineY(x) - gap - CN * 1.3 - EN : lineY(x) - gap;+ return [{ id: id, text: cn, x, y, cap: CN, sw: SWN, align: 'center' }, { id: id + 'E', text: en, x, y: y + CN * 1.3, cap: EN, sw: SWN, align: 'center' }];+};+const dl = (x, y) => d(x, y);+export const LABELS = [+ // Baihetan+ // Butuo+ // the corridor+ ...name('sc', '四川', 'SICHUAN', 105.6, 22),+ { id: 'js', text: '江苏', x: 1858, y: 136, cap: CN, sw: SWN, align: 'center' }, { id: 'jsE', text: 'JIANGSU', x: 1858, y: 136 + CN * 1.3, cap: EN, sw: SWN, align: 'center' },+ { id: 'len', text: '2,080 公里', x: 1300, y: 338.5 - 22 - CN * 1.3 - EN, cap: CN, sw: SWN, align: 'center' }, { id: 'lenE', text: '2,080 km', x: 1300, y: 338.5 - 22 - EN, cap: EN, sw: SWN, align: 'center' },+ // the stations, as the voice names them+ { id: 'csB', text: '换流站', x: BUTUO.c[0], y: BUTUO.c[1] + BR + 3.4, cap: 2.6, sw: 0.25, align: 'center' },+ { id: 'csBE', text: 'CONVERTER STATION', x: BUTUO.c[0], y: BUTUO.c[1] + BR + 7.0, cap: 1.2, sw: 0.22, align: 'center' },+ { id: 'acIn', text: '交流电', x: BUTUO.L[0] - 9, y: BUTUO.c[1] - 6.4, cap: 2.2, sw: 0.24, align: 'center' },+ { id: 'acInE', text: 'AC', x: BUTUO.L[0] - 9, y: BUTUO.c[1] - 3.3, cap: 1.2, sw: 0.22, align: 'center' },+ { id: 'dcOut', text: '直流电', x: BUTUO.c[0] + 21, y: BUTUO.c[1] - 2.4, cap: 2.2, sw: 0.24, align: 'center' },+ { id: 'dcOutE', text: 'DC', x: BUTUO.c[0] + 21, y: BUTUO.c[1] + 0.8, cap: 1.2, sw: 0.22, align: 'center' },+ { id: 'csY', text: '换流站', x: YUCHENG.c[0], y: YUCHENG.c[1] + BR + 3.4, cap: 2.6, sw: 0.25, align: 'center' },+ { id: 'csYE', text: 'CONVERTER STATION', x: YUCHENG.c[0], y: YUCHENG.c[1] + BR + 7.0, cap: 1.2, sw: 0.22, align: 'center' },+ { id: 'acOut', text: '交流电', x: YUCHENG.R[0] + 8.5, y: YUCHENG.c[1] + 3.5, cap: 2.2, sw: 0.24, align: 'center' },+ { id: 'acOutE', text: 'AC', x: YUCHENG.R[0] + 8.5, y: YUCHENG.c[1] + 6.5, cap: 1.2, sw: 0.22, align: 'center' },+ // Yucheng+];+// timestamps: the Butuo tag sits between the + and − lines; Yucheng repeats it above its own, digit for digit+export const TS0 = tag(BUTUO.c[0] + BR + 9.5, BUTUO.c[1] - 1.0, '12:00:00.000', 2.0, 0.24);+// Yucheng: one frame, Butuo's time on top, Yucheng's under it, digit for digit; the difference beside it+const TSX = YUCHENG.c[0] + 13.2, TSY = YUCHENG.c[1] + 9.6;+export const TS1 = { frame: chamferBox(TSX - 1.6, TSY + 0.4, TSX + 21.6, TSY + 10.2, 1), w: 0.3 };+LABELS.push({ id: 'ms7', text: '7 毫秒', x: TSX + 10, y: TSY + 1.8, cap: 3.4, sw: 0.36, align: 'center' }, { id: 'ms7E', text: '7 ms', x: TSX + 10, y: TSY + 6.7, cap: 1.8, sw: 0.3, align: 'center' });+LABELS.push(+);++// ---------- the opening title, printed beside the right-bank generators ----------+LABELS.push(+ { id: 'title', text: '七毫秒', x: d(86, -56)[0], y: d(86, -56)[1], cap: 6.2 * DS, sw: 0.5 * DS, align: 'right' },+ { id: 'titleE', text: 'SEVEN MILLISECONDS', x: d(86, -46.6)[0], y: d(86, -46.6)[1], cap: 2.5 * DS, sw: 0.5 * DS, align: 'right' },+ { id: 'acBus', text: '交流电', x: d(93, -10)[0], y: d(93, -10)[1], cap: 2.6, sw: 0.25, align: 'right' }, { id: 'acBusE', text: 'AC', x: d(93, -7.2)[0], y: d(93, -7.2)[1], cap: 1.2, sw: 0.2, align: 'right' },+);++// ---------- the other ±800 kV lines of the west-to-east corridor (drawn, never lit, never labelled) ----------+// three lanes south of ours; each ends in its own small converter footprint at both ends (routes schematic)+const LM0 = measure(LINE_C);+export const OTHERS = [];+const otherEnds = [+ { d: 11, w0: [505, 692], e: [[1782, 380, 'd'], [1934, 380], [1934, 352]] }, // to Suzhou (Tongli)+ { d: 20, w0: [490, 712], e: [[1760, 398, 'd'], [1974, 398], [2004, 368, 'd']] }, // to Shanghai (Fengxian)+ { d: 29, w0: [475, 732], e: [[1824, 560, 'd']] }, // to Jinhua+];+const OTHER_PADS = [], OTHER_SILK = [];+otherEnds.forEach((o, i) => {+ const lane = offset(LINE_C, -o.d), m = measure(lane);+ let sA = 0; while (sA < m.len && at(m, sA)[0] < 590 + i * 4) sA += 1;+ let sB = m.len; while (sB > 0 && at(m, sB)[0] > 1690 - i * 6) sB -= 1;+ const mid = sub(m, sA, sB), w = octi([[...o.w0], [mid[0][0], mid[0][1], 'd']]);+ const east = octi([mid[mid.length - 1], ...o.e]);+ for (const k of [-1, 1]) {+ const pts = dedupe([...w.slice(0, -1), ...mid, ...east.slice(1)]);+ OTHERS.push({ id: `oth${i}${k}`, pts: offset(pts, k * 1.1), w: 0.9, net: 'idle' });+ }+ for (const p of [o.w0, east[east.length - 1]]) { const b = bridge(p, 2.4, { id: 'ob' + i, sw: 0.18 }); OTHER_PADS.push(...b.pads); OTHER_SILK.push(...b.silk.slice(0, 1)); }+});++// ---------- real cities as test points (the AC grid's nodes): a round pad, a ring, a pinyin tag ----------+const CITIES = [['CHENGDU', 104.07, 30.67], ['CHONGQING', 106.55, 29.56], ['GUIYANG', 106.71, 26.58], ['WANZHOU', 108.41, 30.81], ["XI'AN", 108.94, 34.34],+ ['YICHANG', 111.29, 30.70], ['XIANGYANG', 112.14, 32.04], ['CHANGSHA', 112.94, 28.23], ['WUHAN', 114.31, 30.59],+ ['NANCHANG', 115.86, 28.68], ['ANQING', 117.05, 30.53], ['HEFEI', 117.23, 31.82], ['NANJING', 118.80, 32.06], ['HANGZHOU', 120.16, 30.27],+ ['SHANGHAI', 121.47, 31.23], ['NINGBO', 121.55, 29.87], ['WENZHOU', 120.70, 28.0], ['FUZHOU', 119.30, 26.08], ['GUILIN', 110.29, 25.27]];+export const CITY_PTS = [];++// ---------- silkscreen furniture ----------+const ticks = [];+for (let km = 100; km < 2080; km += 100) if (km % 500) {+ const f = frameAt(LINE_M, LINE_M.len * km / 2080), a = PAIR + 2.6, b = PAIR + 5.2;+ ticks.push({ pts: [[f.p[0] + f.n[0] * a, f.p[1] + f.n[1] * a], [f.p[0] + f.n[0] * b, f.p[1] + f.n[1] * b]], w: 0.55 });+}+// designators and fixed silk (texture: drawn whenever large enough)+export const DESIG = [+ { text: 'G1–G8', x: d(57, 24.2)[0], y: d(57, 24.2)[1], cap: 2.1 * DS, align: 'center' },+ { text: 'G9–G16', x: d(-57, 24.2)[0], y: d(-57, 24.2)[1], cap: 2.1 * DS, align: 'center' },+ ...GENS.map(g => ({ text: g.id, x: g.x, y: g.y - g.h / 2 - 1.9, cap: 0.75 * DS, align: 'center' })),+ { text: 'J2', x: d(-92, 45.6)[0], y: d(-92, 45.6)[1], cap: 1.8 * DS, align: 'center' },+ { text: 'SPILLWAY', x: D[0], y: d(0, -1.5)[1], cap: 1.1 * DS, align: 'center' },+ { text: 'T11', x: T11.c[0], y: T11.c[1] - 4.6, cap: 1.1, align: 'center' }, { text: 'T21', x: T21.c[0], y: T21.c[1] - 4.6, cap: 1.1, align: 'center' },++ { text: 'C11–C14', x: FILT_B.pads[0].x - 1, y: FILT_B.rail + 0.9, cap: 0.75, align: 'left' },+ { text: 'AC FILTER', x: FILT_B.pads[0].x - 1, y: FILT_B.rail + 2.2, cap: 0.75, align: 'left' },+ { text: 'L11', x: REACT[0].pads[0].x + 3.5, y: BUTUO.T[1] - 4.4, cap: 0.9, align: 'center' }, { text: 'L12', x: REACT[1].pads[0].x + 3.5, y: BUTUO.B[1] + 3.3, cap: 0.9, align: 'center' },+ { text: 'L21', x: REACT[2].pads[0].x + 3.5, y: YUCHENG.T[1] - 4.4, cap: 0.9, align: 'center' }, { text: 'L22', x: REACT[3].pads[0].x + 3.5, y: YUCHENG.B[1] + 3.3, cap: 0.9, align: 'center' },+ { text: 'VALVE HALL', x: BUTUO.c[0] - 46, y: BUTUO.c[1] - 20.8, cap: 0.9, align: 'left' }, { text: 'VALVE HALL', x: YUCHENG.c[0] - 46, y: YUCHENG.c[1] - 20.8, cap: 0.9, align: 'left' },+ ...TPS.map((tp, i) => ({ text: 'TP' + (i + 1), x: tp.p[0] + 5, y: tp.p[1] - 1.2, cap: 2.2, align: 'left' })),+ { text: '±800 kV DC · 2,080 km · 8 GW', x: 640, y: 960, cap: 6, align: 'left' },+ { text: 'LAYER 1 OF 4 · COPPER 2 OZ', x: 640, y: 974, cap: 4, align: 'left' },+];+DESIG.push(+ { text: '白鹤滩', x: dl(-100, -56)[0], y: dl(-100, -56)[1], cap: 4.2 * DS, align: 'left' }, { text: 'BAIHETAN', x: dl(-100, -49.6)[0], y: dl(-100, -49.6)[1], cap: 1.8 * DS, align: 'left' },+ ...[['CHONGQING', 108.1], ['ANHUI', 116.75]].map(([t, lon]) => ({ text: t, x: P(lon, 0)[0], y: lineY(P(lon, 0)[0]) - 36, cap: 9, align: 'center' })),+ ...TPS.map(tp => ({ text: tp.text, x: tp.p[0], y: tp.p[1] - 12, cap: 4, align: 'center' })),+);+export const SILK = [+ ...BUTUO.silk, ...YUCHENG.silk, ...T11.silk, ...T21.silk, ...T1.silk, ...FILT_B.silk, ...FILT_Y.silk, ...REACT.flatMap(r => r.silk),+ ...ground([viaB[0] + 1.4, viaB[1]], 1.6, 0.26), ...ground([viaY[0] - 1.4, viaY[1]], 1.6, 0.26, -1),+ ...ground([FILT_B.pads[0].x - 1.6, FILT_B.rail], 1.2, 0.2, -1), ...ground([FILT_Y.pads[0].x - 1.6, FILT_Y.rail], 1.2, 0.2, -1),+ { pts: TS1.frame, w: TS1.w, plot: 'ms7' },+ // valve-hall courtyards (dashed) around both stations+ { pts: box(BUTUO.c[0] - 47, BUTUO.c[1] - 22, BUTUO.c[0] + 49, BUTUO.c[1] + 20), w: 0.22, dash: [1.4, 1] },+ { pts: box(YUCHENG.c[0] - 47, YUCHENG.c[1] - 22, YUCHENG.c[0] + 45, YUCHENG.c[1] + 25), w: 0.22, dash: [1.4, 1] },+ // J2 outline+ { pts: box(J2[0] - 4.6 * DS, J2[1] - 2.4 * DS, J2[0] + 4.6 * DS, J2[1] + 6.9 * DS), w: 0.3 * DS },+ // the dam: generator row outlines, spillway gates, a step-up transformer on every lead+ { pts: box(d(padX(0) - 4, PAD_Y - 4.2)[0], d(0, PAD_Y - 4.2)[1], d(padX(7) + 4, 0)[0], d(0, PAD_Y + 4.2)[1]), w: 0.22 * DS, dash: [1.4 * DS, 1 * DS] },+ { pts: box(d(-padX(7) - 4, PAD_Y - 4.2)[0], d(0, PAD_Y - 4.2)[1], d(-padX(0) + 4, 0)[0], d(0, PAD_Y + 4.2)[1]), w: 0.22 * DS, dash: [1.4 * DS, 1 * DS] },+ ...GENS.flatMap(g => { const y = (g.y + g.h / 2 + d(0, BUS_Y)[1]) / 2, r = 0.55 * DS; return [{ circle: [g.x - r * 0.55, y, r], w: 0.13 * DS }, { circle: [g.x + r * 0.55, y, r], w: 0.13 * DS }]; }),+ // the city module footprint+ { pts: box(CITY_AT[0] - 0.4, CITY_AT[1] - 0.4, CITY_AT[0] + CITY_W * CITY_S + 0.4, CITY_AT[1] + CITY_H * CITY_S + 0.4), w: 0.16 },+ ...ticks, ...OTHER_SILK,+];+export const PADS = [...BUTUO.pads, ...YUCHENG.pads, ...J2PADS, ...T11.pads, ...T21.pads, ...T1.pads, ...FILT_B.pads, ...FILT_Y.pads, ...REACT.flatMap(r => r.pads), ...OTHER_PADS,+ ...TPS.map((tp, i) => ({ x: tp.p[0], y: tp.p[1], r: 2.4, shape: 'round', hole: 0.9, id: 'TP' + i }))];+export const KEEP = [...BUTUO.keep, ...YUCHENG.keep, ...T11.keep, ...T21.keep, ...T1.keep, { rect: [J2[0] - 5 * DS, J2[1] - 2.8 * DS, J2[0] + 5 * DS, J2[1] + 7.3 * DS] },+ { rect: [CITY_AT[0] - 0.8, CITY_AT[1] - 0.8, CITY_AT[0] + CITY_W * CITY_S + 0.8, CITY_AT[1] + CITY_H * CITY_S + 0.8] }];+export const STUBS = TPS.map(tp => ({ id: 'stub' + tp.km, pts: tp.stub, w: 1.2, net: 'dc' }));+TRACES.push(...STUBS.map(t => ({ ...t, m: measure(t.pts) })), ...OTHERS.map(t => ({ ...t, m: measure(t.pts) })));++// board furniture for the closing reveal: holes, fiducials, the title block (title, sheet line, sign-off)+export const HOLES = [[BOARD.x0 + 60, BOARD.y0 + 60], [BOARD.x1 - 60, BOARD.y0 + 60], [BOARD.x0 + 60, BOARD.y1 - 60], [BOARD.x1 - 60, BOARD.y1 - 60]];+export const TITLE = { x: 1120, y: -60, w: 620, h: 270 };+export const FIDS = [[BOARD.x0 + 130, BOARD.y0 + 46], [BOARD.x1 - 46, BOARD.y1 - 130], [BOARD.x0 + 46, BOARD.y1 - 130]];+SILK.push(+ { pts: box(TITLE.x, TITLE.y, TITLE.x + TITLE.w, TITLE.y + TITLE.h), w: 3.2, plot: 'tbBox' },+ { pts: [[TITLE.x, TITLE.y + 190], [TITLE.x + TITLE.w, TITLE.y + 190]], w: 2, plot: 'tbBox' },+);+LABELS.push(+ { id: 'tb', text: '七毫秒', x: TITLE.x + 34, y: TITLE.y + 26, cap: 90, sw: 7, align: 'left' },+ { id: 'tbE', text: 'SEVEN MILLISECONDS', x: TITLE.x + 36, y: TITLE.y + 140, cap: 30, sw: 3.8, align: 'left' },+ { id: 'sign', text: 'LemoLab × Claude Opus 5.5', x: TITLE.x + 38, y: TITLE.y + 214, cap: 30, sw: 3.8, align: 'left' },+);+DESIG.push({ text: 'REV A', x: TITLE.x + TITLE.w - 24, y: TITLE.y + 22, cap: 14, align: 'right' }, { text: 'SHEET 1 OF 1', x: TITLE.x + TITLE.w - 24, y: TITLE.y + 44, cap: 9, align: 'right' });++// reservoir flow: slow, wide+export const RES_FLOW = [{ id: 'res', pts: [d(0, -90), d(0, -5.5)], w: 17 * DS }];+export const CLR = 1.4, VIA_R = 1.6, FENCE_R = 1.15, HOLE_R = 14, FID_R = 5;+export const CHILD = { name: 'city', at: CITY_AT, s: CITY_S };++// ---------- geometry tests ----------+const segDist = (p, a, b) => { const dx = b[0] - a[0], dy = b[1] - a[1], L2 = dx * dx + dy * dy || 1, t = Math.max(0, Math.min(1, ((p[0] - a[0]) * dx + (p[1] - a[1]) * dy) / L2)); return Math.hypot(p[0] - a[0] - t * dx, p[1] - a[1] - t * dy); };+const polyDist = (p, pts) => { let m = 1e9; for (let i = 1; i < pts.length; i++) m = Math.min(m, segDist(p, pts[i - 1], pts[i])); return m; };+const inside = (p, pts) => { let c = false; for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) { const a = pts[i], b = pts[j]; if ((a[1] > p[1]) !== (b[1] > p[1]) && p[0] < (b[0] - a[0]) * (p[1] - a[1]) / (b[1] - a[1]) + a[0]) c = !c; } return c; };+const DAMBOX = [d(-150, -100), d(150, 60)], BTBOX = [[BUTUO.c[0] - 50, BUTUO.c[1] - 26], [BUTUO.c[0] + 60, BUTUO.c[1] + 24]], YCBOX = [[YUCHENG.c[0] - 50, YUCHENG.c[1] - 26], [YUCHENG.c[0] + 75, YUCHENG.c[1] + 32]];+const inBox = (p, b) => p[0] > b[0][0] && p[0] < b[1][0] && p[1] > b[0][1] && p[1] < b[1][1];+function clearOf(p, gap, labels = true) {+ if (p[0] < BOARD.x0 + 30 || p[0] > BOARD.x1 - 30 || p[1] < BOARD.y0 + 30 || p[1] > BOARD.y1 - 30) return false;+ if (inBox(p, DAMBOX) || inBox(p, BTBOX) || inBox(p, YCBOX)) return false;+ if (inside(p, SEA) || polyDist(p, SEA) < gap) return false;+ for (const L of LAKES) if (inside(p, L) || polyDist(p, L) < gap) return false;+ for (const r of RIVER) if (polyDist(p, r.pts) < r.w / 2 + gap) return false;+ for (const t of TRACES) if (t.layer !== 'bottom' && polyDist(p, t.pts) < t.w / 2 + gap) return false;+ if (polyDist(p, LINE_C) < PAIR + 6 + gap) return false;+ if (labels) for (const L of LABELS) { const wd = textWidth(L.text, L.cap); const x0 = L.align === 'center' ? L.x - wd / 2 : L.align === 'right' ? L.x - wd : L.x; if (p[0] > x0 - 6 && p[0] < x0 + wd + 6 && p[1] > L.y - 6 && p[1] < L.y + L.cap + 6) return false; }+ if (p[0] > TITLE.x - 20 && p[0] < TITLE.x + TITLE.w + 20 && p[1] > TITLE.y - 20 && p[1] < TITLE.y + TITLE.h + 20) return false;+ for (const tp of TPS) if (Math.hypot(p[0] - tp.p[0], p[1] - tp.p[1]) < 30) return false;+ for (const c of CITY_PTS) if (Math.hypot(p[0] - c[0], p[1] - c[1]) < 22) return false;+ for (const h of HOLES) if (Math.hypot(p[0] - h[0], p[1] - h[1]) < 40) return false;+ return true;+}+// place the city nodes off the river and the lines (nudged north if needed)+for (const [nm, lon, lat] of CITIES) {+ let [x, y] = P(lon, lat), ok = false;+ for (let k = 0; k < 12 && !ok; k++) { if (clearOf([x, y], 7, false)) ok = true; else y -= 6; }+ if (!ok) continue;+ CITY_PTS.push([x, y]);+ PADS.push({ x, y, r: 3.2, shape: 'round', hole: 1.3, id: 'city' + nm });+ SILK.push({ circle: [x, y, 5.6], w: 0.7 });+ DESIG.push({ text: nm, x: x + 8, y: y - 3, cap: 6.5, align: 'left' });+}+export function fence() {+ const out = [];+ for (const r of RIVER) for (const s of [1, -1]) {+ const o = offset(r.pts, s * (r.w / 2 + 3.2)), m = measure(o);+ for (let x = 3; x < m.len; x += 6.5) {+ const p = at(m, x);+ if (inBox(p, DAMBOX) || inBox(p, BTBOX) || inBox(p, YCBOX) || inside(p, SEA) || p[1] < BOARD.y0 + 20 || p[1] > BOARD.y1 - 20 || p[0] < BOARD.x0 + 20) continue;+ let bad = false; for (const t of TRACES) if (t.layer !== 'bottom' && polyDist(p, t.pts) < t.w / 2 + 2.4) { bad = true; break; }+ if (!bad && polyDist(p, LINE_C) < PAIR + 3.4) bad = true;+ if (!bad) for (const r2 of RIVER) if (r2 !== r && polyDist(p, r2.pts) < r2.w / 2 + 2) { bad = true; break; }+ if (!bad) out.push(p);+ }+ }+ for (const L of LAKES) { const o = L, m = measure([...o, o[0]]); for (let x = 0; x < m.len; x += 6.5) { const q = at(m, x), c = L.reduce((a, b) => [a[0] + b[0] / L.length, a[1] + b[1] / L.length], [0, 0]), dx = q[0] - c[0], dy = q[1] - c[1], k = Math.hypot(dx, dy); out.push([q[0] + dx / k * 4.2, q[1] + dy / k * 4.2]); } }+ return out;+}+export function stitch() {+ const out = [], P0 = 30;+ for (let j = 0, y = BOARD.y0 + 40; y < BOARD.y1 - 30; y += P0 * 0.866, j++) for (let x = BOARD.x0 + 40 + (j % 2) * P0 / 2; x < BOARD.x1 - 30; x += P0) if (clearOf([x, y], 7)) out.push([x, y]);+ return out;+}++LABELS.push(...stepLabel(T1));++// a silkscreen sine beside the AC label on the right-bank bus: back and forth+{ const [x0, y0] = d(85, -3.1), pts = []; for (let i = 0; i <= 48; i++) { const u = i / 48; pts.push([x0 + u * 12, y0 + 1.6 * Math.sin(u * 4 * Math.PI)]); }+ SILK.push({ pts, w: 0.22, plot: 'acBus' }, { pts: [[x0, y0], [x0 + 12.6, y0]], w: 0.1, plot: 'acBus' }); }diff --git a/styles/circuit-board/demo/stills/styleframe.jpg b/styles/circuit-board/demo/stills/styleframe.jpgnew file mode 100644index 0000000..728d9c3Binary files /dev/null and b/styles/circuit-board/demo/stills/styleframe.jpg differdiff --git a/styles/circuit-board/demo/tools/sheet.sh b/styles/circuit-board/demo/tools/sheet.shnew file mode 100644index 0000000..10d8316--- /dev/null+++ b/styles/circuit-board/demo/tools/sheet.sh@@ -0,0 +1,6 @@+#!/bin/sh+# 0.5 s contact sheet at 960x540 into out/sheet.jpg (run from anywhere)+HERE=$(cd "$(dirname "$0")/.." && pwd); LIB=${LIB:-$(cd "$HERE/../../.." && pwd)}; cd "$LIB"+rm -rf "$HERE/out/sheet"; mkdir -p "$HERE/out"+node core/render/still.mjs "$HERE" --range 0:60:0.5 --size 960x540 --out "$HERE/out/sheet" --prefix s_ > /dev/null || exit 1+.venv/bin/python core/render/sheet.py "$HERE/out/sheet.jpg" $(cd "$HERE/out/sheet" && ls s_*.jpg | sort -t_ -k2 -n | sed "s#^#$HERE/out/sheet/#") --cols 8 --w 240diff --git a/styles/circuit-board/demo/tools/srt.py b/styles/circuit-board/demo/tools/srt.pynew file mode 100644index 0000000..f360853--- /dev/null+++ b/styles/circuit-board/demo/tools/srt.py@@ -0,0 +1,16 @@+"""Bilingual subtitles for the film: one cue per spoken line, a Chinese line over an English line, timed like the+subtitle bar the page draws (from each line's start in events.json to the end of its voice file).+Run: python3 <demo>/tools/srt.py <demo> <out.srt>"""+import json, os, sys+D, OUT = sys.argv[1], sys.argv[2]+ev = {e['id']: e for e in json.load(open(os.path.join(D, 'events.json')))['ev'] if e['type'] == 'vo'}+cn = {l['id']: l['text'] for l in json.load(open(os.path.join(D, 'voice/lines.json'), encoding='utf-8'))}+en = dict(json.load(open(os.path.join(D, 'data/subs_en.json'), encoding='utf-8')))+dur = json.load(open(os.path.join(D, 'voice/dur.json')))+ts = lambda t: '%02d:%02d:%02d,%03d' % (t // 3600, t % 3600 // 60, t % 60, round((t - int(t)) * 1000) % 1000)+out = []+for i, k in enumerate(sorted(ev, key=lambda k: ev[k]['t'])):+ t0, t1 = ev[k]['t'] - 0.05, ev[k]['t'] + dur[k] + 0.12+ out.append(f'{i + 1}\n{ts(t0)} --> {ts(t1)}\n{cn[k]}\n{en[k]}\n')+open(OUT, 'w', encoding='utf-8').write('\n'.join(out))+print(OUT, len(out), 'cues')diff --git a/styles/circuit-board/demo/tools/subset.py b/styles/circuit-board/demo/tools/subset.pynew file mode 100644index 0000000..e5d7fe1--- /dev/null+++ b/styles/circuit-board/demo/tools/subset.py@@ -0,0 +1,20 @@+"""Subtitle font: Noto Sans SC (OFL) at weight 500, cut down to the characters the subtitles use.+Run with the library venv: .venv/bin/python -I <demo>/tools/subset.py <demo>+Reads tools/NotoSansSC-VF.ttf (build.sh downloads it), voice/lines.json and data/subs_en.json.+Writes fonts/NotoSansSC-Medium-sub.ttf. The board's own lettering is drawn in code (src/font.js, src/hanzi.js)."""+import json, os, sys+from fontTools.ttLib import TTFont+from fontTools.varLib.instancer import instantiateVariableFont+from fontTools import subset+D = sys.argv[1]+cn = ''.join(l['text'] for l in json.load(open(os.path.join(D, 'voice/lines.json'), encoding='utf-8')))+en = ''.join(t for _, t in json.load(open(os.path.join(D, 'data/subs_en.json'), encoding='utf-8')))+chars = {c for c in cn + en + '0123456789,.·×→≈~' if c.strip()}+f = TTFont(os.path.join(D, 'tools/NotoSansSC-VF.ttf'))+instantiateVariableFont(f, {'wght': 500}, inplace=True)+opt = subset.Options(); opt.name_IDs = ['*']; opt.notdef_outline = True+s = subset.Subsetter(opt); s.populate(unicodes=[ord(c) for c in chars] + [0x20]); s.subset(f)+f.save(os.path.join(D, 'fonts/NotoSansSC-Medium-sub.ttf'))+cmap = f.getBestCmap(); miss = sorted(c for c in chars if ord(c) not in cmap)+print('subtitle font:', len(cmap), 'glyphs', '(missing: ' + ''.join(miss) + ')' if miss else '')+sys.exit(1 if miss else 0)diff --git a/styles/circuit-board/demo/voice/dur.json b/styles/circuit-board/demo/voice/dur.jsonnew file mode 100644index 0000000..95c1096--- /dev/null+++ b/styles/circuit-board/demo/voice/dur.json@@ -0,0 +1,13 @@+{+ "v01": 4.881,+ "v02": 4.342,+ "v03": 4.028,+ "v04": 4.391,+ "v05": 3.987,+ "v06": 3.317,+ "v07": 6.753,+ "v08": 7.743,+ "v09": 5.847,+ "v10": 4.362,+ "v11": 3.957+}\ No newline at end of filediff --git a/styles/circuit-board/demo/voice/lines.json b/styles/circuit-board/demo/voice/lines.jsonnew file mode 100644index 0000000..4a294b2--- /dev/null+++ b/styles/circuit-board/demo/voice/lines.json@@ -0,0 +1,49 @@+[+ {+ "id": "v01",+ "text": "四川深山里发出来的电,仅仅七毫秒后,就到了两千公里外的江苏。",+ "asr": "四川深山里发出来的电,仅仅7毫秒后,就到了2000公里外的江苏。"+ },+ {+ "id": "v02",+ "text": "平时我们家里用的电,电流是来回摆动着走的,叫做交流电。"+ },+ {+ "id": "v03",+ "text": "如果直接送去太远的地方,在路上就会白白损耗掉很多。"+ },+ {+ "id": "v04",+ "text": "所以,电得先进一趟换流站,变成只朝一个方向跑的直流电。"+ },+ {+ "id": "v05",+ "text": "然后再顺着这根两千多公里长的电线,一路狂奔到江苏。",+ "asr": "然后再顺着这根2000多公里长的电线,一路狂奔到江苏。"+ },+ {+ "id": "v06",+ "text": "全程只要七毫秒,连眨一下眼睛的时间都不到。",+ "asr": "全程只要7毫秒,连眨一下眼睛的时间都不到。"+ },+ {+ "id": "v07",+ "text": "到了终点站,它会被重新变回交流电,再把电压一级一级降下来,最终送进你家墙上的插座里。"+ },+ {+ "id": "v08",+ "text": "而当你插上手机充电器时,充电头里其实也藏着一个叫整流桥的小零件,正在把交流电重新变回直流电。"+ },+ {+ "id": "v09",+ "text": "说出来你可能不信,它和换流站里那个几层楼高的大家伙,用的是同一个电路原理。"+ },+ {+ "id": "v10",+ "text": "只不过,换流站那边的功率,是这个小充电头的整整四亿倍。"+ },+ {+ "id": "v11",+ "text": "你手机里的每一格电,都是跨越千山万水,这么跑过来的。"+ }+]\ No newline at end of filediff --git a/styles/circuit-board/demo/voice/words.json b/styles/circuit-board/demo/voice/words.jsonnew file mode 100644index 0000000..383e2e2--- /dev/null+++ b/styles/circuit-board/demo/voice/words.json@@ -0,0 +1,1399 @@+{+"v01": [+[+"四",+-0.2,+0.16+],+[+"川",+0.16,+0.36+],+[+"深",+0.36,+0.52+],+[+"山",+0.52,+0.7+],+[+"里",+0.7,+0.84+],+[+"发",+0.84,+1.04+],+[+"出来",+1.04,+1.26+],+[+"的",+1.26,+1.38+],+[+"电,",+1.38,+1.54+],+[+"仅",+1.92,+2.0+],+[+"仅",+2.0,+2.18+],+[+"7",+2.18,+2.36+],+[+"毫",+2.36,+2.48+],+[+"秒",+2.48,+2.62+],+[+"后",+2.62,+2.92+],+[+"就",+2.92,+3.22+],+[+"到了",+3.22,+3.44+],+[+"2000",+3.44,+3.8+],+[+"公",+3.8,+3.96+],+[+"里",+3.96,+4.12+],+[+"外",+4.12,+4.26+],+[+"的",+4.26,+4.36+],+[+"江",+4.36,+4.5+],+[+"苏。",+4.5,+4.74+]+],+"v02": [+[+"平",+-0.16,+0.16+],+[+"时",+0.16,+0.36+],+[+"我们",+0.36,+0.56+],+[+"家",+0.56,+0.74+],+[+"里",+0.74,+0.88+],+[+"用",+0.88,+1.0+],+[+"的",+1.0,+1.1+],+[+"电,",+1.1,+1.26+],+[+"电",+1.56,+1.72+],+[+"流",+1.72,+1.92+],+[+"是",+1.92,+2.1+],+[+"来",+2.1,+2.22+],+[+"回",+2.22,+2.4+],+[+"摆",+2.4,+2.56+],+[+"动",+2.56,+2.72+],+[+"着",+2.72,+2.84+],+[+"走",+2.84,+3.0+],+[+"的,",+3.0,+3.18+],+[+"叫",+3.44,+3.58+],+[+"做",+3.58,+3.74+],+[+"交",+3.74,+3.86+],+[+"流",+3.86,+4.04+],+[+"电。",+4.04,+4.2+]+],+"v03": [+[+"如果",+-0.2,+0.16+],+[+"直接",+0.16,+0.42+],+[+"送",+0.42,+0.66+],+[+"去",+0.66,+0.8+],+[+"太",+0.8,+0.98+],+[+"远",+0.98,+1.12+],+[+"的",+1.12,+1.26+],+[+"地方,",+1.26,+1.54+],+[+"在",+1.9,+1.98+],+[+"路",+1.98,+2.12+],+[+"上",+2.12,+2.38+],+[+"就",+2.38,+2.62+],+[+"会",+2.62,+2.74+],+[+"白",+2.74,+2.86+],+[+"白",+2.86,+3.02+],+[+"损",+3.02,+3.16+],+[+"耗",+3.16,+3.36+],+[+"掉",+3.36,+3.5+],+[+"很多。",+3.5,+3.76+]+],+"v04": [+[+"所以,",+0.02,+0.34+],+[+"电",+0.76,+0.84+],+[+"德",+0.84,+1.0+],+[+"先",+1.0,+1.16+],+[+"进",+1.16,+1.34+],+[+"一",+1.34,+1.48+],+[+"趟",+1.48,+1.6+],+[+"换",+1.6,+1.76+],+[+"流",+1.76,+1.92+],+[+"站,",+1.92,+2.12+],+[+"变",+2.38,+2.52+],+[+"成",+2.52,+2.7+],+[+"只",+2.7,+2.82+],+[+"朝",+2.82,+3.0+],+[+"一个",+3.0,+3.16+],+[+"方",+3.16,+3.34+],+[+"向",+3.34,+3.52+],+[+"跑",+3.52,+3.68+],+[+"的",+3.68,+3.8+],+[+"直",+3.8,+3.94+],+[+"流",+3.94,+4.1+],+[+"电。",+4.1,+4.24+]+],+"v05": [+[+"然后",+-0.06,+0.26+],+[+"再",+0.26,+0.5+],+[+"顺",+0.5,+0.66+],+[+"着",+0.66,+0.78+],+[+"这",+0.78,+0.92+],+[+"根",+0.92,+1.02+],+[+"2000",+1.02,+1.34+],+[+"多",+1.34,+1.52+],+[+"公",+1.52,+1.66+],+[+"里",+1.66,+1.76+],+[+"长",+1.76,+1.94+],+[+"的",+1.94,+2.06+],+[+"电",+2.06,+2.18+],+[+"线,",+2.18,+2.5+],+[+"一",+2.72,+2.84+],+[+"路",+2.84,+2.94+],+[+"狂",+2.94,+3.14+],+[+"奔",+3.14,+3.3+],+[+"到",+3.3,+3.46+],+[+"江",+3.46,+3.6+],+[+"苏。",+3.6,+3.84+]+],+"v06": [+[+"全",+-0.2,+0.16+],+[+"程",+0.16,+0.32+],+[+"只",+0.32,+0.46+],+[+"要",+0.46,+0.56+],+[+"7",+0.56,+0.74+],+[+"毫",+0.74,+0.9+],+[+"秒,",+0.9,+1.08+],+[+"连",+1.42,+1.54+],+[+"长",+1.54,+1.68+],+[+"一下",+1.68,+1.86+],+[+"眼",+1.86,+2.12+],+[+"睛",+2.12,+2.24+],+[+"的",+2.24,+2.34+],+[+"时间,",+2.34,+2.62+],+[+"都",+2.86,+2.92+],+[+"不到。",+2.92,+3.1+]+],+"v07": [+[+"到了",+-0.16,+0.16+],+[+"终",+0.16,+0.34+],+[+"点",+0.34,+0.5+],+[+"站,",+0.5,+0.74+],+[+"他",+1.04,+1.12+],+[+"会",+1.12,+1.24+],+[+"被",+1.24,+1.36+],+[+"重",+1.36,+1.54+],+[+"新",+1.54,+1.76+],+[+"变",+1.76,+1.86+],+[+"回",+1.86,+2.04+],+[+"交",+2.04,+2.18+],+[+"流",+2.18,+2.34+],+[+"店,",+2.34,+2.52+],+[+"再",+2.86,+2.96+],+[+"把",+2.96,+3.1+],+[+"电",+3.1,+3.24+],+[+"压",+3.24,+3.42+],+[+"一",+3.42,+3.6+],+[+"级",+3.6,+3.72+],+[+"一",+3.72,+3.86+],+[+"级",+3.86,+4.02+],+[+"降",+4.02,+4.16+],+[+"下",+4.16,+4.36+],+[+"来,",+4.36,+4.56+],+[+"最",+4.74,+4.86+],+[+"终",+4.86,+5.04+],+[+"送",+5.04,+5.2+],+[+"进",+5.2,+5.36+],+[+"你",+5.36,+5.5+],+[+"家",+5.5,+5.66+],+[+"墙",+5.66,+5.86+],+[+"上",+5.86,+6.02+],+[+"的",+6.02,+6.12+],+[+"插",+6.12,+6.28+],+[+"座",+6.28,+6.46+],+[+"里。",+6.46,+6.64+]+],+"v08": [+[+"而",+-0.22,+0.1+],+[+"当",+0.1,+0.22+],+[+"你",+0.22,+0.36+],+[+"插",+0.36,+0.5+],+[+"上",+0.5,+0.66+],+[+"手",+0.66,+0.8+],+[+"机",+0.8,+0.96+],+[+"充",+0.96,+1.1+],+[+"电",+1.1,+1.24+],+[+"器",+1.24,+1.42+],+[+"时,",+1.42,+1.72+],+[+"充",+1.98,+2.16+],+[+"电",+2.16,+2.3+],+[+"头",+2.3,+2.48+],+[+"里,",+2.48,+2.72+],+[+"其实",+2.92,+3.1+],+[+"也",+3.1,+3.3+],+[+"藏",+3.3,+3.46+],+[+"着",+3.46,+3.6+],+[+"一个",+3.6,+3.78+],+[+"叫",+3.78,+4.06+],+[+"整",+4.06,+4.22+],+[+"流",+4.22,+4.38+],+[+"桥",+4.38,+4.5+],+[+"的",+4.5,+4.62+],+[+"小",+4.62,+4.78+],+[+"零",+4.78,+4.96+],+[+"件,",+4.96,+5.16+],+[+"正",+5.44,+5.56+],+[+"在",+5.56,+5.7+],+[+"把",+5.7,+5.82+],+[+"交",+5.82,+5.96+],+[+"流",+5.96,+6.12+],+[+"电",+6.12,+6.3+],+[+"重",+6.3,+6.58+],+[+"新",+6.58,+6.82+],+[+"变",+6.82,+6.94+],+[+"回",+6.94,+7.1+],+[+"直",+7.1,+7.26+],+[+"流",+7.26,+7.42+],+[+"电。",+7.42,+7.62+]+],+"v09": [+[+"说",+-0.18,+0.18+],+[+"出来",+0.18,+0.42+],+[+"你",+0.42,+0.56+],+[+"可能",+0.56,+0.74+],+[+"不",+0.74,+0.96+],+[+"信,",+0.96,+1.18+],+[+"他",+1.5,+1.64+],+[+"和",+1.64,+1.76+],+[+"换",+1.76,+1.9+],+[+"流",+1.9,+2.04+],+[+"站",+2.04,+2.2+],+[+"里",+2.2,+2.42+],+[+"那个",+2.42,+2.74+],+[+"几",+2.74,+2.92+],+[+"层",+2.92,+3.08+],+[+"楼",+3.08,+3.22+],+[+"高",+3.22,+3.36+],+[+"的",+3.36,+3.48+],+[+"大家",+3.48,+3.68+],+[+"伙,",+3.68,+4.08+],+[+"用",+4.38,+4.46+],+[+"的是",+4.46,+4.62+],+[+"同",+4.62,+4.88+],+[+"一个",+4.88,+5.1+],+[+"电",+5.1,+5.24+],+[+"路",+5.24,+5.38+],+[+"原",+5.38,+5.54+],+[+"理。",+5.54,+5.74+]+],+"v10": [+[+"只",+-0.2,+0.12+],+[+"不",+0.12,+0.22+],+[+"过,",+0.22,+0.42+],+[+"换",+0.8,+0.88+],+[+"流",+0.88,+1.02+],+[+"站",+1.02,+1.18+],+[+"那",+1.18,+1.3+],+[+"边",+1.3,+1.44+],+[+"的",+1.44,+1.52+],+[+"功",+1.52,+1.64+],+[+"率,",+1.64,+1.86+],+[+"是",+2.1,+2.18+],+[+"这个",+2.18,+2.38+],+[+"小",+2.38,+2.56+],+[+"充",+2.56,+2.7+],+[+"电",+2.7,+2.86+],+[+"头",+2.86,+3.1+],+[+"的",+3.1,+3.26+],+[+"整",+3.26,+3.56+],+[+"整",+3.56,+3.74+],+[+"四",+3.74,+3.94+],+[+"一",+3.94,+4.1+],+[+"倍。",+4.1,+4.22+]+],+"v11": [+[+"你",+-0.22,+0.1+],+[+"手",+0.1,+0.26+],+[+"机",+0.26,+0.42+],+[+"里",+0.42,+0.52+],+[+"的",+0.52,+0.62+],+[+"每",+0.62,+0.76+],+[+"一",+0.76,+0.94+],+[+"格",+0.94,+1.06+],+[+"店",+1.06,+1.24+],+[+"都是",+1.24,+1.7+],+[+"跨",+1.7,+1.9+],+[+"越",+1.9,+2.06+],+[+"千",+2.06,+2.22+],+[+"山",+2.22,+2.38+],+[+"万",+2.38,+2.54+],+[+"水,",+2.54,+2.82+],+[+"这么",+3.04,+3.22+],+[+"跑",+3.22,+3.42+],+[+"过",+3.42,+3.56+],+[+"来",+3.56,+3.72+],+[+"的。",+3.72,+3.84+]+]+}\ No newline at end of filediff --git a/styles/circuit-board/demo/voice_en/dur.json b/styles/circuit-board/demo/voice_en/dur.jsonnew file mode 100644index 0000000..932716f--- /dev/null+++ b/styles/circuit-board/demo/voice_en/dur.json@@ -0,0 +1,13 @@+{+ "v01": 4.555,+ "v02": 4.383,+ "v03": 3.271,+ "v04": 4.391,+ "v05": 3.863,+ "v06": 3.346,+ "v07": 5.607,+ "v08": 5.737,+ "v09": 5.8,+ "v10": 4.358,+ "v11": 3.875+}\ No newline at end of filediff --git a/styles/circuit-board/demo/voice_en/lines.json b/styles/circuit-board/demo/voice_en/lines.jsonnew file mode 100644index 0000000..7d84e61--- /dev/null+++ b/styles/circuit-board/demo/voice_en/lines.json@@ -0,0 +1,68 @@+[+ {+ "id": "v01",+ "text": "Power made deep in the mountains of Sichuan reaches Jiangsu, 2,000 km away, in just 7 milliseconds.",+ "say": "Power in Sichuan reaches Jiangsu, two thousand kilometres away, in seven milliseconds.",+ "rate": "+25%",+ "asr": "Power in Sichuan reaches Jiangsu, 2,000 km away in 7ms."+ },+ {+ "id": "v02",+ "text": "The electricity in our homes swings back and forth as it flows. It's called alternating current, AC.",+ "say": "The electricity in our homes, swings back and forth. It's called alternating current.",+ "rate": "+25%",+ "asr": "The electricity in our homes swings back and forth. It's called alternating current."+ },+ {+ "id": "v03",+ "text": "Sent that far as it is, a lot of it would simply be lost on the way."+ },+ {+ "id": "v04",+ "text": "So first it goes through a converter station and becomes direct current, DC, flowing one way only.",+ "say": "It goes through a converter station and becomes direct current, flowing one way only.",+ "rate": "+25%",+ "asr": "It goes through a converter station and becomes direct current, flowing one way only."+ },+ {+ "id": "v05",+ "text": "Then it races along this line, more than 2,000 km long, all the way to Jiangsu.",+ "say": "Then it races along this line, more than two thousand kilometres, to Jiangsu.",+ "rate": "+25%",+ "asr": "Then it races along this line, more than 2,000 kilometers, to Jiangsu."+ },+ {+ "id": "v06",+ "text": "The whole trip takes 7 milliseconds, less than the blink of an eye.",+ "say": "The whole trip takes seven milliseconds, less than the blink of an eye.",+ "rate": "+20%"+ },+ {+ "id": "v07",+ "text": "At the end it's turned back into AC, stepped down level by level, and sent to the socket in your wall.",+ "say": "At the end it's turned back into alternating current, stepped down level by level, and sent to the socket in your wall.",+ "asr": "At the end it's turned back into alternating current, stepped down level by level, and sent to the socket in your wall."+ },+ {+ "id": "v08",+ "text": "Plug in your phone charger, and inside it a tiny part called a bridge rectifier turns the AC back into DC.",+ "say": "Plug in your phone charger, and inside it a tiny part called a bridge rectifier turns the A C back into D C."+ },+ {+ "id": "v09",+ "text": "Believe it or not, it works on the same circuit principle as the giant, storeys tall, in the converter station.",+ "rate": "+18%",+ "asr": "Believe it or not, it works on the same circuit principle as the giant, stories tall, in the converter station."+ },+ {+ "id": "v10",+ "text": "Only the station's power is a full 400 million times that of this little charger.",+ "say": "Only the station's power is a full four hundred million times that of this little charger.",+ "rate": "+18%"+ },+ {+ "id": "v11",+ "text": "Every bar of charge on your phone came this far, across mountains and rivers.",+ "rate": "+12%"+ }+]\ No newline at end of filediff --git a/styles/circuit-board/poster.jpg b/styles/circuit-board/poster.jpgnew file mode 100644index 0000000..728d9c3Binary files /dev/null and b/styles/circuit-board/poster.jpg differdiff --git a/styles/circuit-board/style.json b/styles/circuit-board/style.jsonnew file mode 100644index 0000000..0af10e0--- /dev/null+++ b/styles/circuit-board/style.json@@ -0,0 +1,19 @@+{+ "slug": "circuit-board",+ "num": "76",+ "en": "Circuit Board",+ "cn": "电路板",+ "category_en": "Information & Keynote",+ "category_cn": "信息与发布",+ "film": "Seven Milliseconds",+ "line": "The whole story is a printed circuit board seen from above: rivers are channels in the copper, places are pads, words are silkscreen, and the current runs along the traces from a dam 2,080 km to a phone charger.",+ "line_cn": "整个故事画成一块俯视的电路板:江河是铜皮里的沟槽,地方是焊盘,字是丝印;电流顺着走线,从水坝跑过 2,080 公里,一直跑进手机充电器。",+ "uses": [+ "How energy and signals travel",+ "Supply chains and routes, end to end",+ "Inside a device or a system",+ "Same mechanism at two scales"+ ],+ "frame_sec": 58.0,+ "dur": 60.0+}