gnuplot gallery · examples/param.lms
Parametric plots
parametric curves and a pm3d sphere (gnuplot param.dem)
Loading the WebAssembly host…
What runs
The page fetches examples/param.bin, 1,910 bytes of lmcode bytecode
(sha256 5e0e6026e58c…), 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.
# Demo param.dem: parametric plots and a parametric pm3d sphere.
mkdir("images");
mkdir("build");
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
plot.script("set parametric\nset dummy t\nset samples 160\nset key box\nset key below");
# Image 1: conic sections.
plot.png("images/param-1.png", 800, 600);
plot.script("set xrange [-3:3]\nset yrange [-3:3]\nset title 'Parametric Conic Sections'");
plot.cmd("plot -t,t,cos(t),cos(2*t),2*cos(t),sin(t),-cosh(t),sinh(t)");
plot.close();
# Image 2: sin(t)/t and cos(t)/t against each other.
plot.png("images/param-2.png", 800, 600);
plot.script("set autoscale x\nset yrange [-1.5:1.5]\nset trange [0.0001:10*pi]\nset title 'sin(t)/t, cos(t)/t'");
plot.cmd("plot sin(t)/t,cos(t)/t");
plot.close();
# Image 3: surface parametrised by u,v, coloured with pm3d.
plot.png("images/param-3.png", 800, 700);
plot.cmd("reset");
plot.cmd("set label 1 \"Decouple range of parametric axes u/v\\nfrom that of display axes x/y/z\" at screen 0.1, 0.9");
plot.script("unset colorbox\nset palette cubehelix cycle 3\nset view equal xyz\nset view 120, 300\nset xyplane 0\nset pm3d depthorder\nset border 4095\nset tics scale 0\nset format ''\nset angles radians");
plot.script("xx(u, v) = cos(v) * cos(u)\nyy(u, v) = cos(v) * sin(u)\nzz(u, v) = sin(v)\ncolor(u, v) = sin(2*u)+sin(2*v)");
plot.script("set parametric\nset isosamples 121, 61\nset samples 121, 61\nset urange [-pi:pi]\nset vrange [-pi/2:pi/2]\nset xrange [-1:1]\nset yrange [-1:1]\nset zrange [-1:1]");
plot.cmd("splot '++' using (xx($1,$2)):(yy($1,$2)):(zz($1,$2)):(color($1,$2)) with pm3d notitle");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/param-3.png images/param.png;
assert(cp.code == 0);
println("wrote images/param.png (and images/param-1.png .. images/param-3.png)");