gnuplot gallery · examples/hidden.lms
Hidden-line removal
hidden3d on explicit surfaces (gnuplot hidden.dem)
Loading the WebAssembly host…
What runs
The page fetches examples/hidden.bin, 1,249 bytes of lmcode bytecode
(sha256 57adf9eba5a0…), 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.
# hidden.dem: hidden-line removal on explicit surfaces.
mkdir("images");
mkdir("build");
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
plot.script("set samples 20\nset isosamples 20\nset hidden3d");
# Image 1: a bell-shaped surface.
plot.png("images/hidden-1.png", 800, 600);
plot.cmd("set title 'Hidden line removal of explicit surfaces'");
plot.script("set xrange [-3:3]\nset yrange [-2:2]");
plot.cmd("splot 1 / (x*x + y*y + 1)");
plot.close();
# Image 2: sin*cos with a z grid, full border, and contours from above.
plot.png("images/hidden-2.png", 800, 600);
plot.script("set view 60,30\nset xrange [-3:3]\nset yrange [-3:3]\nset zrange [-1:1]");
plot.script("set ztics -1,0.5,1\nset grid z\nset border 4095");
plot.cmd("splot sin(x) * cos(y)");
plot.close();
# Image 3: same surface viewed from behind with contours.
plot.png("images/hidden-3.png", 800, 600);
plot.script("unset grid\nset ztics autofreq\nset border 31\nset view 75,230\nset contour");
plot.cmd("splot sin(x) * cos(y)");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/hidden-2.png images/hidden.png;
assert(cp.code == 0);
println("wrote images/hidden.png (and images/hidden-1.png .. images/hidden-3.png)");