Skip to content

The preview

The Preview card at the top right of CURIO Code runs the script in the editor and shows what it draws on a 64 × 64 grid of LEDs. It needs no panel and no account.

Press Run (or Shift+Ctrl+Enter, Shift+⌘+Enter on a Mac). Press it again after you change the script: the preview does not follow your typing. Stop ends it.

The preview is not an imitation of the panel written for the browser. It is the panel’s own script engine, the same C and C++ code the firmware is built from, compiled to WebAssembly. So a script behaves in the preview as it does on a panel:

  • the same Lua, with the panel’s 32-bit numbers;
  • the same limits on work, memory and shader cost, and the same errors when a script goes over them;
  • the same error messages, with the same line numbers;
  • the same pixels. Drawing, noise, sin, cos, tan, shaders (interpreted and compiled) and 3D are the same arithmetic, and the preview’s build is tested, frame by frame and bit for bit, against the firmware code built natively.

The Interpreted / Compiled switch applies to the preview as it does to an upload. On Compiled, fragment() is compiled and the preview runs the script with its bytecode, through the same shader VM as the panel.

Part What it tells you
The LEDs The frame the script drew
The state line Running, stopped, or the script’s error
The estimate Roughly how long this frame would take on a real panel
Lua work Lua instructions used this frame, of the 2,000,000 allowed
Shader cost Compiled shader cost used this frame, of the 1,000 allowed
Memory The script’s memory, of the 512 KB allowed
The console What the script printed with print(...), and how the last compile went

A figure turns red when it reaches 90% of its limit.

print is the easiest way to see what a script is doing. On a panel its output goes to the serial port, where you need a USB cable to read it; here it appears under the picture.

Speed. Your computer runs Lua fifty to a hundred times faster than the panel does, so everything is smooth in the preview. A shader that manages 8 frames per second on the panel looks perfect here. That is what the estimate is for: it is worked out from the frame’s Lua instructions and compiled shader cost, using timings measured on a real panel. It does not count time spent inside drawing calls (long lines, big rectangles, 3D), so treat it as a lower bound for scripts that draw a lot.

Colour. A monitor is not an LED panel. Brightness and colour will not match exactly.

Six functions. exp, log, a power other than 2 (x ^ 3), asin, acos and atan come from the C library, which is not the same one in the browser as on the panel. A result can differ in its last digit, which once in a while is one step of colour in one pixel.

A script that gets stuck. The work limit stops a Lua loop that never ends, here and on the panel. It cannot stop a single built-in call that takes very long, such as a string.find with a pathological pattern. On a panel that freezes the display. The preview notices when a frame has not finished within a second, stops the script and tells you.

The Uniforms card sends to the preview as well as to a connected panel. A value you send stays set for the scripts you run afterwards, as it does on the panel. See Animation and uniforms.

The engine is a file of about 230 KB (about 100 KB over the network). It is downloaded the first time you press Run, not when the page opens, and your browser keeps it afterwards. The console shows how long that first Run took.

Next: Drawing.