Write a look

A look decides how a run is drawn: where the nodes sit, what a crash looks like, which moment gets a pulse. It observes the trace and can never change what happens (the visual layer). If you write no look, every program is drawn by std/look/basic. This guide makes a small look for the module of chapter 4; chapter 12 teaches the same ideas step by step.

1. A package for the look

A look is an ordinary package. Add a folder ticklook next to the tick package, with a file ticklook/ticklook.synod. The package that counts is the one synod new tick --module example.com/tick writes.

# package ticklook
use std/look
use std/sim
use std/theme

# Every node gets the standard card, in a row instead of a ring
when sim.Started
  look.Layout "row"

when (sim.Added n)
  draw (look.Card for n) as card for n

# A crashed node fades and gets a red outline
when (sim.Crashed n)
  look.Fade (card of n) to 0.3
  look.Stroke (card of n) with theme.Critical

2. Turn it on

A look is active when the program imports it. In the main file, import the look package:

# package main
use example.com/tick/tick
use example.com/tick/ticklook
use std/sim

define main
  set first to (sim.Spawn tick)
  after 3s
    sim.Crash first
  sim.StopAt 6s

The import is used because the package contains observers. Run the folder and watch: in the Mac app the stage updates as you save, and on the command line synod run tick --summary shows the same run as text. A mistake in a look is a look failure: the simulation is still correct, the scene stops at that fact and synod run says look failed at with the position.

3. Colors

Use the names of std/theme (theme.Ink, theme.Paper, theme.Line, theme.Quiet, theme.Accent, theme.Good, theme.Warning, theme.Critical) so your look matches the rest. To add your own, give a color a name with a phrase that has no holes; a color literal is allowed only as its result. The scene lists it as ticklook.Hot.

# package ticklook
# The color of a node that has counted a lot
define Hot
  result #E86F5A

The values of the standard palette are in the std/theme table and the rules in §9.5. Labels are drawn in the player's sans at one size; a look cannot change it in Synod 0.2.

4. What you can draw

std/look has shapes (Circle, Rect, Label, Line, Group, Card), changes (Fill, Stroke, Fade, Pulse, Effect), placement (Layout, Place, Orbit, Center) and motion (Tween, Travel, Flight). The std/look reference lists every phrase with its pattern and the layout rules are in §9.4. Two forms matter most:

Looks and invariants are also how a program tells its story: the program emits a fact and the look draws it (chapter 13).

Next