Render scenes and animation with lmdraw
These commands were run in an empty directory on Linux arm64 with lmscript 0.2.482 and the lmdraw v0.2.7 release binary. The tool cache path in step 1 is shortened to CACHE; everything else is real output.
1. Install the tools
lmctl from npm provides lmscript. lmscript install fetches the lmdraw release into the tool cache; a script with an install declaration does the same on first run.
npm install -g @lmctl-ai/lmctl
lmscript --version lmscript 0.2.482 lmscript install github:lmctl-ai/lmdraw@latest tag: v0.2.7 path: CACHE/lmscript/tools/github/lmctl-ai/lmdraw/latest/lmdraw sha256: 16b9198594de4462333a2af21df43b14ec8a4dcf6db4e213174eb19b32e66f45 source: tool cache
2. Run a published example
Every example in the repository is a self-contained script. lmscript can run one straight from its URL; it writes the PNG below images/ in the current directory.
lmscript https://raw.githubusercontent.com/lmctl-ai/lmdraw/main/examples/title-card.lms wrote images/title-card.png file images/title-card.png images/title-card.png: PNG image data, 960 x 540, 8-bit/color RGBA, non-interlaced

3. Write and check your own scene
Save this as card.lms. The outer script holds the title; the block measures it, centers the heading, underlines it to the measured width and returns that width to the script.
mkdir("images");
title = "Quarterly review";
p = _lmcode_ cli="lmdraw" install="github:lmctl-ai/lmdraw@latest";
scene.canvas(640, 360, "#152438");
let card = scene.rect(36.0, 36.0, 568.0, 288.0, "#1f344b");
card.set_attr("stroke", "#6fbdb4");
card.set_attr("stroke-width", "2");
let w = scene.measure_text(${title}, 38.0, true);
let heading = scene.text(320.0, 170.0, 38.0, ${title}, "#f5f8fb");
heading.set_attr("text-anchor", "middle");
heading.set_attr("font-weight", "700");
scene.line(320.0 - w / 2.0, 190.0, 320.0 + w / 2.0, 190.0, "#f5c16c", 3.0);
scene.render_png("images/card.png", 640, 360, 2);
lmcode_return_set(w);
end _lmcode_
r = run_lmcode(p);
require(r.ok, json_stringify(r));
println(json_stringify(r));
Compile-check the block against the host schema without running it, then run it. The render scale of 2 doubles the pixel dimensions.
lmscript --check card.lms && echo checked
checked
lmscript card.lms
{"ok":true,"result":321.5179748535156}
file images/card.png
images/card.png: PNG image data, 1280 x 720, 8-bit/color RGBA, non-interlaced
4. Draw a diagram with shapes and connectors
Save this as flow.lms. A grid supplies cell anchors, boxes and a diamond carry their own labels, and connectors join named anchors.
mkdir("images");
p = _lmcode_ cli="lmdraw" install="github:lmctl-ai/lmdraw@latest";
scene.canvas(600, 360, "#101820");
let slots = scene.grid(60.0, 60.0, 480.0, 240.0, 2, 3, 20.0, 20.0);
let order = scene.box(slots.cell(0, 0), "c", 120.0, 44.0, "order", "#1e3247", "#4a6a88", 8.0, 14.0);
let gate = scene.diamond(300.0, 120.0, 130.0, 70.0, "in stock?", "#1e3247", "#f5c16c", 13.0);
let ship = scene.box(slots.cell(2, 1), "c", 120.0, 44.0, "ship", "#1e3247", "#6fbdb4", 22.0, 14.0);
scene.connector(order, "e", gate, "w", "straight", "none", "arrow", "none", "#8fb4d9", 2.0, "", 0.5, 0.0, 0.0);
scene.connector(gate, "s", ship, "n", "elbow", "none", "arrow", "6 5", "#8fb4d9", 2.0, "yes", 0.4, 8.0, 0.0);
scene.render_png("images/flow.png", 600, 360, 1);
end _lmcode_
r = run_lmcode(p);
require(r.ok, json_stringify(r));
println("wrote images/flow.png");
lmscript flow.lms wrote images/flow.png file images/flow.png images/flow.png: PNG image data, 600 x 360, 8-bit/color RGBA, non-interlaced
5. Load an SVG and render a 24-frame tween
Save this as tween.lms. The script writes a small SVG under assets/, the only folder load_svg reads. The block takes a retained handle to the element with id dot, recolors it, and moves it across 24 numbered frames.
mkdir("images");
mkdir("assets");
svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"320\" height=\"120\" viewBox=\"0 0 320 120\">";
svg = svg + "<rect id=\"plate\" x=\"10\" y=\"10\" width=\"300\" height=\"100\" rx=\"12\" fill=\"#1f344b\"/>";
svg = svg + "<circle id=\"dot\" cx=\"60\" cy=\"60\" r=\"24\" fill=\"#f5c16c\"/></svg>";
write_file("assets/badge.svg", svg);
p = _lmcode_ cli="lmdraw" install="github:lmctl-ai/lmdraw@latest";
let dot = scene.load_svg("assets/badge.svg", "dot");
dot.set_attr("fill", "#6fbdb4");
for (i in range(0, 24)) {
let t = float(i) / 23.0;
dot.set_attr("cx", str(lerp(60.0, 260.0, ease(t))));
scene.render_png("images/badge-" + str(i) + ".png", 320, 120, 1);
}
end _lmcode_
r = run_lmcode(p);
require(r.ok, json_stringify(r));
println("wrote 24 frames");
lmscript tween.lms wrote 24 frames ls images/badge-*.png | wc -l 24 file images/badge-23.png images/badge-23.png: PNG image data, 320 x 120, 8-bit/color RGBA, non-interlaced
6. Encode the frames as MP4
ffmpeg combines the numbered PNGs into a one-second H.264 video at 24 frames per second. ffprobe confirms its codec and dimensions.
ffmpeg -hide_banner -loglevel error -framerate 24 -start_number 0 -i 'images/badge-%d.png' -frames:v 24 -c:v libx264 -pix_fmt yuv420p -movflags +faststart -y badge.mp4 && echo encoded encoded ffprobe -v error -select_streams v:0 -show_entries stream=codec_name,width,height,r_frame_rate -show_entries format=duration -of default=noprint_wrappers=1 badge.mp4 codec_name=h264 width=320 height=120 r_frame_rate=24/1 duration=1.000000
7. Read a host refusal
Save this as bad.lms. It renders to a folder the host does not allow. run_lmcode does not throw; it returns the refusal as data, with the line and column inside the block.
p = _lmcode_ cli="lmdraw" install="github:lmctl-ai/lmdraw@latest";
scene.canvas(320, 120, "#101820");
scene.render_png("out/card.png", 320, 120, 1);
end _lmcode_
r = run_lmcode(p);
println(json_stringify(r));
lmscript bad.lms
dsl line 3:7: PNG output must be a .png file directly under build/rendered/ or images/
{"ok":false,"phase":"run","code":"RUN_HOST","message":"dsl line 3:7: PNG output must be a .png file directly under build/rendered/ or images/","line":3,"column":7}
8. Confirm the render is repeatable
The same binary writes the same bytes for the same script. Hash the card, run it again and hash it again.
sha256sum images/card.png
5e82d80122d3da543aa5231832368ec5a1de077c993309583b74acbb25ddca80 images/card.png
lmscript card.lms
{"ok":true,"result":321.5179748535156}
sha256sum images/card.png
5e82d80122d3da543aa5231832368ec5a1de077c993309583b74acbb25ddca80 images/card.png
What you learned
Declare the host on an _lmcode_ block, check it with lmscript --check, run it with run_lmcode and test r.ok. Scenes are retained: keep handles, change attributes and render again for each frame. Outputs go under images/ or build/rendered/, SVG input comes from assets/, and numbered frames are the input to ffmpeg. The guide explains the model and the reference lists every method.