Spill: Unbalanced cells
Big reveal: Cells can have two sides. A “from” and a “to”.
$: cell("W").color("white")
$: cell("B").color("black")
$: cell("U").from("W").to("B")
In the above snippet, the “U” cell is defined as changing from white to black.
This means: If you use it on the left-hand-side of a rule, it checks for white cells. If you use it on the right-hand-side of a rule, it changes cells to black.
$: cell("W").color("white")
$: cell("B").color("black")
$: cell("U").from("W").to("B")
$: rule().diagram("U => U")
The above rule changes all white cells to black.
For brevity, you might want to use anonymous cells here.
$: cell("U")
.from(cell().color("white"))
.to(cell().color("black"))
$: rule().diagram("U => U")
This kind of ‘unbalanced’ cell can be helpful when modifying colours and moving a cell at the same time.
Let’s say you have two cells: One that matches any colour with red above zero (“R”). And one that decreases red by a little bit (“D”).
$: cell("R").red(1,255)
$: cell("D").red(x => x - 16)
to be continued