gnuplot gallery · examples/image.lms

Binary RGB image

binary RGB image, rotated copies (gnuplot image.dem)

Loading the WebAssembly host…

What runs

The page fetches examples/image.bin, 1,699 bytes of lmcode bytecode (sha256 4c27a927781b…), 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.

# image.dem: plotting a binary RGB image, and rotated/translated copies.
mkdir("images");
mkdir("build");
if (!file_exists("examples/data/blutux.rgb")) {
  mkdir("examples/data");
  dl = system curl -fsSL -o examples/data/blutux.rgb https://raw.githubusercontent.com/lmctl-ai/lmplot/main/examples/data/blutux.rgb;
  assert(dl.code == 0);
}
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
# Data: examples/data/blutux.rgb, 128x128 RGB bytes (path relative to the repo root).
# Image 1: the penguin with a label.
plot.png("images/image-1.png", 800, 600);
plot.cmd("set title \"Larry Ewing's GIMP penguin on vacation basking in\\nthe balmy waters off the coast of Murmansk\"");
plot.script("set xrange [-10:137]\nset yrange [-10:157]");
plot.cmd("set label '\"I flew here... by plane.  Why?  For the halibut.\"' at 64,135 center");
plot.cmd("plot 'examples/data/blutux.rgb' binary array=(128,128) flipy format='%uchar' with rgbimage");
plot.close();
# Image 2: four copies translated and rotated.
plot.png("images/image-2.png", 800, 600);
plot.cmd("reset");
plot.cmd("set title 'Translations of position variables via using'");
plot.script("set xrange [-10:275]\nset yrange [-10:300]\nunset key");
plot.cmd("set label '\"Time for a dip...\"' at 132,285 center");
plot.cmd("f = 'examples/data/blutux.rgb'");
plot.cmd("plot f binary array=(128,128) flipy center=(64,201) format='%uchar' with rgbimage, f binary array=(128,128) flipy rotation=-90d center=(201,201) format='%uchar' with rgbimage, f binary array=(128,128) flip=y rotate=3.1415 center=(201,64) format='%uchar' with rgbimage, f binary array=(128,128) flip=y rot=0.5pi center=(64,64) format='%uchar' using 1:2:3 with rgbimage");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/image-1.png images/image.png;
assert(cp.code == 0);
println("wrote images/image.png (and images/image-1.png .. images/image-2.png)");