Plotter G-Code
I've been reading a bit about Marlin G-Code, and working on a typst library that turns simple instructions into G-Code & draws them using typst.
Here's the code for the image above:
#import "gcode.typ": ctx, move, line, printer-dimensions
#set page(
width: printer-dimensions.x,
height: printer-dimensions.y,
margin: 0mm,
)
#ctx(
move(50, 50),
line(0, 100),
move(0, -50),
line(30, 0),
line(0, 50),
line(0, -100),
move(20, 0),
line(0, 50),
move(-10, 30),
line(20, 0),
move(-10, 10),
line(0, -20),
move(20, -70),
)
Please note that the library isn't stable (well, it's not on Typst Universe even) and the interface will change.
Eventually I want to add
- higher-level functions for drawing more complex shapes
- boolean operations
Curve
This is a task for another day (so not 2026-02-15), but cetz's arc and marlin's arc functions have completely different parameters. Marlin's is similar to SVG's though, so maybe I should take a look at cetz's sources.
Code style
I need to switch to CETZ-style body ({} this thing instead of an argument array) because that would allow using loops and stuff.
Status
I'm archiving the entire area as it would take up too much time and I'd rater work on trk.
This particular note may be resurrected eventually