gnuplot gallery · examples/turntable.lms
Turntable frames
a loop rendering a rotating surface as 8 frames
Loading the WebAssembly host…
What runs
The page fetches examples/turntable.bin, 1,812 bytes of lmcode bytecode
(sha256 76598e387587…), and hands it to the same lmplot.wasm every example uses.
The bytecode calls the host's Plot functions (plot.cmd, plot.data, plot.num,
plot.png …); gnuplot draws into an in-memory file system and the page shows the files the program wrote.
In SVG mode plot.png("x.png", w, h) writes x.svg with gnuplot's svg terminal; PNG mode uses lmplot's
own rasterizer and fonts, the same bytes as the native binary.
The program was compiled ahead of time from the source on the right with lmscript; the lmscript lines around the
_lmcode_ block (data generation, ${...} values, run_lmcode) ran at compile time.
# Turntable: render a rotating 3D surface as N PNG frames from a DSL loop.
# A plain .gp script would need a do-for with `set output sprintf(...)`; here the
# loop, the file names and the view angle are ordinary typed lmscript code, and
# each frame is one plot.png / plot.close pair.
# Writes images/turntable-0.png ... turntable-7.png.
mkdir("images");
mkdir("build");
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
# scene set up once: identical axes, ranges and colours in every frame
plot.cmd("set samples 40, 40");
plot.cmd("set isosamples 40, 40");
plot.cmd("set xrange [-8:8]");
plot.cmd("set yrange [-8:8]");
plot.cmd("set zrange [-0.3:1]");
plot.cmd("set ticslevel 0");
plot.cmd("set hidden3d");
plot.cmd("set pm3d");
plot.cmd("set palette defined (0 'dark-blue', 0.5 'light-green', 1 'orange-red')");
plot.cmd("set cbrange [-0.3:1]");
plot.cmd("unset key");
plot.cmd("set xlabel 'x'");
plot.cmd("set ylabel 'y'");
plot.cmd("set zlabel 'z'");
let frames = 8;
for (k in range(0, frames)) {
let angle = 360 * k / frames; # azimuth in degrees: 0, 45, ..., 315
let file = "images/turntable-" + str(k) + ".png";
plot.png(file, 480, 480);
plot.cmd("set view 60, " + str(angle));
plot.cmd("set title 'sin(r)/r surface, view 60, " + str(angle) + "'");
plot.cmd("splot sin(sqrt(x**2+y**2))/sqrt(x**2+y**2) with pm3d");
plot.close();
plot.echo("frame " + str(k) + " -> " + file);
}
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/turntable-3.png images/turntable.png;
assert(cp.code == 0);
println("wrote images/turntable.png (and images/turntable-0.png .. images/turntable-7.png)");