summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 01:19:32 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitf555cf75c08ed84c90ebf366a0edea4479bf8f1c (patch)
tree18de5b1d49a3b3cce6f1d2831d74e9c0ccaa926d /README.md
parent9d10fc880bf4e62f8421d351ce15bddeec075322 (diff)
downloadsketchbook-f555cf75c08ed84c90ebf366a0edea4479bf8f1c.tar.gz
sketchbook-f555cf75c08ed84c90ebf366a0edea4479bf8f1c.zip
README: PDF pages and parts, in the Animation section
A paragraph on a PDF page as a Typst object: the absolute path Typst's root / allows, and that the cache does not see the file change; text as outlines; the order write follows; what a page costs, measured on Figure 2-1's page (parse once 6-12 ms, 0.9-1.7 ms a frame to record for the GPU, 0.4 ms on it, 2-5 ms on the CPU renderer), a table of contents five times that, and the bench's page budget. One on part: the rectangle (centre and size in the object's units, the literal s.rect takes), how to pick it (the guides, or pdftotext -bbox and the points to units sum), where the part stands and when it shows, the rest drawn by the object, a shape to the first part, rules crossing fields, and transformInto into the whole target so a morph can be split. One on examples/manual.zig, -Dmanual and what happens without the PDF. The examples list names it, and the objects list names part. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'README.md')
-rw-r--r--README.md54
1 files changed, 52 insertions, 2 deletions
diff --git a/README.md b/README.md
index 8cf2998..bf2aacb 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,7 @@ The standalone example packages live in [`examples/`](examples/):
- [`micscope`](examples/micscope/): records the microphone or opens sound files, plays them either way, and shows waveform, spectrogram and spectrum; a tuner.
- [`spheres`](examples/spheres/): the three-body problem on the GPU, each body a voice synthesised by a compute shader.
- [`talk.zig`](examples/talk.zig): a talk with a slider in it, a sketch that runs its own `anim.Deck` (`zig build test-talk` plays it).
+- [`manual.zig`](examples/manual.zig): Figure 2-1 of the Intel SDM comes alive, a PDF page as vector shapes and parts of it (`zig build manual -Dmanual=PDF`; see Animation, PDF pages and parts).
Run `zig build run` inside a package, with `zig build lib --watch` in a second
terminal for hot reload. `zig build test` runs its headless checks;
@@ -523,8 +524,8 @@ fn wobble(now: anim.Now, swing: anim.Value) anim.Pose {
```
Objects are added (`typst`, `svg`, `rect`, `circle`, `line`, `arrow`,
-`polygon`, `custom`) and show in the order they were added; each call
-returns a handle. Animations are methods of the handle: `write`, `create`,
+`polygon`, `custom`, and `part` of another) and show in the order they
+were added; each call returns a handle. Animations are methods of the handle: `write`, `create`,
`fadeIn`, `fadeOut`, `transformInto`, `move(.{ .x, .y, .scale, .rotation,
.opacity })`, `scaleTo`, `rotate`, `indicate`; plus `anim.camera(...)` and
`value.to(x)`. `play` runs a tuple (or array) of them together; its
@@ -567,6 +568,55 @@ file, reads `scene.typst_sources`, compiles each with `typst compile`
(cached by content in `.zig-cache/typst`) and embeds the SVGs. Nothing
scans files, and a scene without Typst needs no `typst`.
+**PDF pages and parts.** Typst imports a page of a PDF as vector paths,
+so a page is a Typst object like any other:
+`s.typst("#image(\"/home/me/sdm.pdf\", page: 31)", .{})`. Typst runs with
+`/` as its root, so an absolute path names the file where it lies; the
+file is not part of the cache key, so one changed in place needs its entry
+in `.zig-cache/typst` gone. Text is outlines: every glyph is a filled
+shape (nothing to search or select), drawn crisp at any camera zoom, and
+`write` reveals the shapes in the order the PDF draws them (in the Intel
+SDM: header and footer, the text from the top, then the figures). A page
+costs what its shapes do: Figure 2-1's page of the SDM is 2.1 MB of SVG
+and 1954 shapes, parsed once, 6-12 ms, the first frame it shows; then, at
+1280x720 in a release build, 0.9-1.7 ms a frame to record for the GPU
+(0.4 ms on the GPU itself) or 2-5 ms on the CPU renderer. A table of
+contents, dot leaders and all, is five times that: show a part of it.
+`zig build bench` times the page beside the simple objects, with a budget
+of its own. An SVG a Typst object includes (`image("x.svg")`) is kept the
+same way.
+
+`s.part(page, .{ .x, .y, .w, .h })` takes the shapes whose bounds' centre
+lies in a rectangle out of an object, as an object of its own, so a field
+of a figure or a row of a table can glow, be written, fly off or morph
+while the page around it stays. The rectangle is in the object's units,
+its centre and size: the literal `s.rect` takes to cover the same place
+when the object stands at the origin at scale 1. Pick it with the guides
+(G: lay the page at the origin, at scale 1, and read the pointer), or
+from `pdftotext -bbox -f N -l N file.pdf -`, whose points from the
+top-left of a W x H pt page are `(x - W/2) * 4/3` across and
+`(y - H/2) * 4/3` down. The part stands where its shapes stood, around
+the rectangle's centre (so `indicate`, `scaleTo` and `rotate` turn it in
+place), and shows as the object does after the plays laid so far: taken
+from a page that has faded in, it is there. The object draws the rest
+from then on, at every instant. A shape goes to the first part that
+takes it, so a rule that crosses several fields (a box's outline) stays
+with whichever holds its centre: keep areas inside the rules. Parts of
+parts, and of any vector object, work the same way, and share the
+object's geometry (a page is parsed once however many parts it gives).
+`transformInto` morphs into the whole of its target, so a morph's result
+can be split by parts taken after it: `c0.transformInto(bits)`, then
+`s.part(bits, ...)` for each run of bits.
+
+`examples/manual.zig` is a talk on Figure 2-1 of the SDM (Vol. 2, page
+31): the fields of the instruction format glow in turn, `83 C0 01` is
+written below, each byte flies into its field and `C0` splits into
+`11 000 000` over Mod, Reg and R/M. `zig build manual` plays it in a
+window; the PDF is `-Dmanual=PATH` (`~/01-resources/intel-devref-ii.pdf`
+by default), never part of the repository: without it the example builds
+a scene that says so, and its script (`test/manual.script`, in `zig build
+test` when the file is there) is skipped.
+
**Custom objects** are drawn by the scene's own code with 2D commands
(`sk.draw`, `f.fill`, `f.text`): what is runtime data, a register table, a
memory grid, a code panel. `s.custom(&data, pose)` adds one, where `data`