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)
It’s simple to use these on cells that are standing still / not moving.
$: cell("R").red(1,255)
$: cell("D").red(subtract(1))
$: rule().from("R").to("D")
In the rule above, any cell with some redness inside gets its red reduced until it runs out.
But what if you want to do this while also moving the cell?
$: cell("R").red(1,255)
$: cell("D").red(subtract(1))
$: rule().from("RX").to("XD")
In this rule, the coder’s intention was for the reddish cell (R) to move to the right while losing a bit of redness (D). However, the Spill language has no way of knowing that the cells R and D are supposed to associated with each other in any way. So in this case, it’ll accidentally end up reducing the redness of whatever was at that location, which was actually cell X… which could be anything! Because X is a completely symbolic cell (see partial colours).
Are you following??
What you need to do is this:
$: cell("R").red(1,255)
$: cell("D").red(subtract(1))
$: cell("U").from("R").to("D")
$: rule().from("UX").to("XU")
Now we’re using the same unbalanced cell (U) on both sides of our role, so Spill knows to treat those two cells as one. The value of U on the right-hand-side will be based on the value of U on the left-hand-side.
there’s more. back to the spill