lmdraw

lmdraw logo

lmdraw is a native host for retained 2D scenes written in lmscript: an _lmcode_ block builds a scene from shapes, text, diagram blocks and imported SVG, and the host renders deterministic PNG files or numbered frames. This page is the quick reference for lmdraw 0.2.7; the linked pages hold the details.

A dark title card with gold and teal accents, rendered by lmdraw.
A title card made from retained shapes and text nodes.

Install and run

Install lmctl, which provides the lmscript compiler and runner. A script that declares the lmdraw host downloads the release binary into the lmscript tool cache on first use. Release binaries are built for Linux x86-64 and arm64 with glibc 2.35 or newer.

npm install -g @lmctl-ai/lmctl
lmscript install github:lmctl-ai/lmdraw@latest
lmscript --check scene.lms
lmscript scene.lms
lmctl autorun https://raw.githubusercontent.com/lmctl-ai/lmdraw/main/examples/hohmann-transfer.lms

Minimal example

Save this as scene.lms and run it with lmscript scene.lms. It writes images/card.png at 1280 by 720 pixels and prints the result envelope returned by run_lmcode.

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));
lmscript scene.lms
{"ok":true,"result":321.5179748535156}

Host protocol and CLI flags

Scripts normally reach the host through run_lmcode. The flags below are the protocol the compiler and runner use, and they are useful for inspection.

CommandEffect
lmdraw --versionPrints the version, for example lmdraw 0.2.7.
lmdraw --lmcode-schema --jsonPrints the embedded schema JSON the compiler checks blocks against: dsl.schema 2, name lmdraw, context scene of type Scene, six host types.
lmdraw --lmcode-schemaPrints the compact per-type summary of host members.
lmdraw --schema and lmdraw --schema --jsonEarlier spellings of the same two outputs; still accepted.
lmdraw --lmcode-signaturesPrints every registered signature, one per line: 1 context, 46 host methods and 206 standard signatures in 0.2.7.
lmdraw --lmcode FILE.dslb [FILE.dslb ...]Verifies every compiled program file, then runs them in order in one process. run_lmcode calls this for you.
Exit codeMeaning
0Success.
2Invalid command line (code CLI_USAGE).
3Program file load or verification failed, or a host call failed while running.
4Another application failure.

Scene API at a glance

The block has one context object, scene, of type Scene. Coordinates are float CSS pixels with the origin at the upper left and y growing down; text y is the baseline. Write float arguments with a decimal point.

TypeMembersUse
Scene (context scene)canvas, load_svg, render_pngStart a scene with a size and background or from an SVG file under assets/, and write a PNG under images/ or build/rendered/.
Scenerect, circle, ellipse, line, arrow, polyline, path, text, imagePrimitive constructors; each returns a Node.
Scenebox, diamond, cylinder, note, cluster, grid, connectorLabeled diagram shapes (Shape), an invisible layout grid (Grid) and routed edges between coordinates or shape anchors.
Scenelifeline, message, activation, self_messageSequence-diagram notation; each returns a Group.
Sceneaxes, log_axes, legendLinear and logarithmic plot axes and a multi-series legend; each returns a Group.
Scenegroup, linear_gradient, load_font, measure_textGrouping, gradient paint, TrueType fonts from assets/fonts/, and text width in pixels.
Nodeset_attr(name, value)Update an SVG-style attribute such as fill, stroke, opacity, transform, font-weight, text-anchor, marker-end or stroke-dasharray. Values are strings.
Shapeset_attr, cx, cyStyle the shape body and read its center. Anchors are n, s, e, w, ne, nw, se, sw and c.
Gridcell(col, row)Returns the cell as a Shape for placing boxes and connectors.
Groupadd(Node), add(Group), set_attrCollect children and style them together.
Gradientstop(offset, color)Add color stops; paint with a fill or stroke of the form url(#id).
LimitValue
Canvas1 to 4096 pixels per side and at most 8,000,000 pixels.
Render scaleInteger 1 to 4; scaled output at most 8,000,000 pixels.
OutputA .png file directly under images/ or build/rendered/.
InputsSVG directly under assets/ (at most 2 MiB); TrueType fonts directly under assets/fonts/ (at most 8 MiB); images only as embedded PNG data URIs.
Scene sizeAt most 10,000 nodes, 1,024 gradients and 128 stops per gradient.

Standard library

lmdraw 0.2.7 registers 206 lmcode_std_v3 signatures: strings, encoding, math, collections, queues, stacks, priority queues, Json, templates, files and the lmcode_return functions. The current lmcode_std_v3 catalog has 226 signatures; the 20 added REST and CLI signatures are not in the 0.2.7 binary and arrive when lmdraw next syncs the standard library and releases. The reference page lists both sets.

More