A solid drawn as cross-sections, one terminal per section.
A volume of N×N×N voxels is cut three ways, N sheets across each axis, and each sheet is an ordinary terminal showing where a turning solid's surface crosses it. One sheet on its own is a flat picture of one slice. Stack 3N terminals in space as transparent sheets, in three families each perpendicular to the other two, and the solid appears in depth from every side: whichever way it is turned, one family faces the viewer while the other two are edge on.
lattice does not know whether it is in such a stack. Every instance turns
the solid by the wall clock and draws only its own slice, so any number of
them, in any terminals, stay in step with nothing between them.
go install github.com/0magnet/lattice/cmd/lattice@latest
lattice --axis z --slice 7 # one sheet
lattice --axis y --tile # every sheet of the y axis, side by side
lattice --shape torus --once # one frame, printed, and done
The middle front sheet of the sphere:
────────────
╱╱╱╱── ──╲╲╲╲
╱╱╱╱ ╲╲╲╲
╱╱╱╱ ╲╲╲╲
││╱╱ ╲╲││
││││ ││││
││ ││
││ ││
││││ ││││
││╲╲ ╱╱││
╲╲╲╲ ╱╱╱╱
╲╲╲╲ ╱╱╱╱
╲╲╲╲── ──╱╱╱╱
────────────
A sheet is as many voxels square as its terminal has rows (or half its
columns, if that is fewer), a voxel being two characters wide so that it is
square: 2n columns by n rows. The same n is the number of sheets in every
family, so the terminal's resolution is the volume's, in all three dimensions:
zoom a terminal out to more, smaller characters and the program, told of the
new size as programs are, draws a finer slice of a finer volume. -n pins it
instead. -slice counts from the far side toward the viewer the family faces,
and is the middle by default.
| axis | seen from | right | up |
|---|---|---|---|
z |
the front | x | y |
x |
the right side | −z (the front is on the left) | y |
y |
above | x | −z (the front is at the bottom) |
Each is read unmirrored from its own side and mirrored from the other, as a sign painted on glass is. A voxel is lit when the surface passes through it, decided per voxel, so the three sheets through a voxel always agree, and it is colored by where it is, so it is the same color in all three.
-shape: sphere, torus, cube, octahedron, gyroid.-style lines(the default) writes the line the surface makes across the sheet,─ │ ╱ ╲, and·where the surface lies along the sheet instead;asciiis the same in- | / \ .;shadewrites how squarely the surface crosses the sheet,.:-=+*#;solidfills every lit voxel.-spinand-pitchturn and tilt the solid, in degrees a second and degrees.-monois one green;-no-color(orNO_COLOR) none at all.-fpsis the frames a second, 20 by default, and must be above zero.-figure FILEdraws lines and points instead of a solid: a trajectory, a wire-frame, a cloud of dots, writtenx y za line with a blank line between polylines, and scaled to fit. A voxel is lit where the figure passes through it, and written as the way the figure runs across the sheet:─ │ ╱ ╲, or·where it runs through the sheet instead; a lone point is•.
Only the cells that changed are sent, so a mostly still, mostly empty sheet costs almost nothing to keep on screen.
The command is lattice.Program, so a host that keeps its own terminals can
run it in them frame by frame: the same flags, writing the same bytes.
p, err := lattice.NewProgram([]string{"-axis", "y", "-slice", "3"}, os.Stderr)
if err != nil {
return err
}
p.Enter(term) // term: any io.Writer a terminal reads
for t := range frames {
p.Frame(t) // the solid as it stands at t
}
p.Leave()A host with a figure that changes, a model that moves, hands every program the
same *lattice.Figure with p.Show(f) and f.Set(lines) when it moves: the
figure is voxelized once for all of them.
Sheet, BasisOf and Render are the geometry underneath it, for a host
that places the sheets in space.
The arrow keys turn the solid five degrees a press, ← and → about the vertical,
↑ and ↓ toward and away from you; r puts it back, q quits. Every sheet has
to be told, and tmux's synchronize-panes is exactly that: one keypress in
every pane.
A host that turns the stack itself can send each program a pose instead, on its input, as an operating system command a terminal ignores:
ESC ] lattice ; pose ; w ; x ; y ; z BEL
a unit quaternion applied to the solid after its own turning (PoseSequence
writes one). The inverse of the stack's turn holds the solid still while the
stack turns; the turn itself turns the solid with the view while the stack
stands still. A program that has not been moved draws nothing new.
Every sheet of every axis, each in a tmux window of its own:
for a in x y z; do for k in $(seq 0 15); do tmux new-window -d "lattice --axis $a --slice $k"; done; done
Flat, that is 48 pictures of slices. The solid is only there when they are stacked: chaosrack is to show them that way, as real terminals drawn as transparent sheets in 3-D.
Made with goda:
go run github.com/loov/goda@latest graph github.com/0magnet/lattice/... | dot -Tsvg -o docs/lattice-goda-graph.svg
Made with gocloc (excludes vendor/, node_modules/, .git/):
gocloc --not-match-d='(vendor|node_modules|\.git)' .
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Go 15 161 295 1582
Markdown 1 36 0 136
Makefile 1 21 52 105
YAML 1 0 7 98
Bourne Shell 1 8 17 31
-------------------------------------------------------------------------------
TOTAL 19 226 371 1952
-------------------------------------------------------------------------------