Loading editor...

About reactivity

Reactivity means that derived variables automatically recompute whenever their dependencies change. Define a scalar t, build angles and sizes from it, and every update to t propagates through the entire dependency chain instantly - no manual refresh needed.

A reactive square

The setup below builds a square whose size and rotation are both driven by a single parameter t:

  • : t = \scalar 0
  • : t-plus-1 = \add t 1
  • : angle = \mul t 90
  • : side = \mul 2 t-plus-1
  • : \square p0 side angle

Now change t and watch everything update:

t-plus-1, angle, side, and the square all recompute immediately. The entire chain is driven by a single value.


Animating t

Because everything depends on t, animating t animates the whole structure. The animation-speed variable controls how fast t changes each frame:

  • : t = \scalar 0
  • : animation-speed = \scalar 0.001
  • : \animate t 1
  • : \animate t 0

The square grows and rotates smoothly as t sweeps between 0 and 1 - driven entirely by two lines of derivation.


\copy: a non-reactive snapshot

\copy produces a static copy of an object's current state. The copy is detached from the reactive graph - upstream changes no longer reach it.

  • : \copy poly0

The live square redraws; the copy does not move.

This pattern can be repeated to build up a sequence of snapshots at different values of t:

The canvas now shows five static snapshots alongside the live square. None of the copies responded to any change in t.


\translate and \rotate also break reactivity

Transforming a reactive object with \translate or \rotate also cuts its reactive connection. The result is a new static object.

\translate

Start fresh, draw a line, and compute its midpoint:

  • : \line a b
  • : m = \mid-point line0

At this point m is reactive - move a and m follows:

  • : a = \point 0 0

Now translate m:

  • : \translate m 1 0
  • : a = \point -2 0

After \translate, m is a fixed point. Its dependency on a (through line0) is gone.


\rotate

  • : \rotate m p0 90
  • : a = \point -3 0

The outcome is the same: \rotate produces a new static result, detached from the reactive chain.


The rule is consistent: reactive objects stay reactive until a structural operation (\copy, \translate, \rotate) creates a new static result. Everything upstream continues to update normally - only the transformed or copied result is frozen.