Text output (exactly what node cli.js prints)
Ten pieces of cloth written in LOOM. Each one is a short program; click a piece to open it in the editor, then use Loom & debugger to watch it being woven.
The spec's example programs, run live in this page by the same engine cli.js uses, compared character for character with their expected output.
Weaving in one minute
A loom holds long vertical warp threads, one per column. Each warp thread passes through a heddle on one of eight shafts. To weave a row (a pick) you lift some shafts, which raises every thread on them, and pass the weft thread across. A raised thread shows its own color in that row; everywhere else the weft covers it. Row after row, patterns appear from nothing but the threading and the order of lifts.
A LOOM program describes that process. Its output is a grid of color letters, one per crossing, with . for rows never woven. The Cloth tab paints that grid with the palette's colors; Loom & debugger replays it pick by pick.
Statements
loom W H | Must come first. W warp threads (1–200) and room for H picks (1–200). |
palette k=#rrggbb … | Names colors with single letters a–z. |
warp seq | Colors every warp thread. The sequence repeats across the width. |
thread seq | Puts each thread on a shaft 1–8, repeating like warp. |
treadle N lift | Saves a lift as treadle N (1–10), used later as tN. |
shuttle seq | Weft colors taken in turn by picks that don't name a color. |
pick [color] lift | Weaves one row with that weft color and lift. |
cross I J | Swaps the threads in columns I and J (color and shaft). |
drift N / drift -N | Rotates every thread N columns to the right (or left), wrapping around. |
maxfloat N | From here on, stops with an error if a float is longer than N. |
repeat N { … } | Runs the lines in between N times (1–1000). Blocks nest. |
One statement per line. // starts a comment.
Sequences
a b c | three elements |
a*3 | a a a |
(a b)*2 | a b a b |
mirror(a b c) | a b c b a (there and back without repeating the turn) |
1-4, 4-1 | 1 2 3 4 and 4 3 2 1 (shaft sequences only) |
Lifts
13 | shafts 1 and 3 |
- / * | no shafts / all shafts |
!12 | every shaft except 1 and 2 |
t2 | whatever treadle 2 lifts (in pick only) |
Floats
A float is a thread that stays on the same side for several crossings in a row. Long floats make loose cloth that snags. After maxfloat N, every pick checks the new row (weft floats, left to right) and then every column (warp floats, counting all rows so far). The debugger's float strip shows each column's current run.
Errors
The first error stops the program, and the whole output is one line such as error line 5: unknown color 'q'. Studio marks that line in red in the editor. Block problems (bad repeat, unexpected '}', unclosed block) and a missing loom header are found before anything runs; everything else is caught when its line executes.
Keys
Ctrl+Enter runs the program. On the Loom tab, ←/→ step, Space plays or pauses, and Home/End jump to either end.