Livecoding Workflow
triode supports both quick in-browser sketching and host-application embedding.
Recommended loop
- Start in a fast sketch context (global mode or playground).
- Keep edits to one cue and retain JSX mesh keys across compatible changes.
- Transition to non-global mode for host integration and multi-instance reliability.
Runtime modes
liveMode: "continuous": persistent runtime; best for live editing.liveMode: "restart": full reset each eval; best for strict reruns.- Per-eval override:
triode.eval(code, { mode, reset, hush }).
Dynamic Water
In Dynamic Water Geometry, click the preview and use WASD or the arrow keys to move. Drag to turn, and use Tab to leave the preview. Change i / 5 to i / 9 in the first block and press Alt+Enter with the caret in that block to change the wave spacing from the current viewpoint. To keep a slider live in the wave rule, declare its reader in the same block, for example const amount = liveParam("speed", o0), and call amount() in the rule.
deformHeight((i, t) => …).out(o0) writes a height rule to the scene on o0. A mesh in that scene registers its local vertex heights with useHeightSurface(meshRef, speed). The callback gets the vertex index and elapsed wave time. Keep it synchronous and side-effect-free, and return a finite height for every vertex. The cue validates the complete set of heights and stages a frame before publishing. If a published rule later fails, the scene tries the previous rule at the current phase. If it also fails, the scene keeps the last complete heights until that rule can run again or a new rule is published.
The scene block owns the surface, texture and WalkCamera input. Running the scene block alone starts a new surface with the original wave. Running the display block alone changes the displayed output. The wave block needs a registered surface on its destination, and a full buffer can set up both at once.
Global vs non-global
Hydra-style global sketching:
const triode = await Triode.create({ makeGlobal: true, detectAudio: false });
osc(8, 0.1, 0.8).render();
Host-safe embedding:
const triode = await Triode.create({ makeGlobal: false, detectAudio: false });
const H = triode.synth;
H.osc(8).out(H.o0);
H.render(H.o0);
Playground usage
Use the interactive playground for fast recipe edits and sharable links:
- Playground Guide
- Published page:
https://triode.live/playground/index.html
Rehearse mesh motion
Open Torus Pulse. Its scene block wraps the torus in <Motion> and publishes it to o1. The next block sends src(o1) to o0, and the last selects the display. Use Alt+Enter to run the block under the cursor.
- Set Spin to zero to hold the current angle. Raise it to resume from that angle.
- In the scene block, change
Math.sin(t * 2)toMath.sin(t * 4)and run the block. The pulse follows the new expression at the current time. Compatible edits keep accumulated spin and the camera pose. - In the mix block, change
src(o1).out(o0)tosrc(o1).kaleid(3).out(o0)and run it while the torus moves. - In Orbit Cluster, change the amplitude in
rotationXand run the scene block. The circle of spheres wobbles together while its Y spin continues.
spinX and spinY are angular rates in radians per second. rotationX adds an angle in radians to the accumulated X spin. scale is the absolute uniform scale. Each accepts a finite number or a function of elapsed seconds. Motion carries spin into an edited scene when a single top-level Motion wraps one child of the same type and key at the same position in the scene tree. A rejected scene edit leaves the previous cue playing.
Lifecycle hygiene
- Call
triode.dispose()when replacing runtime instances. - In host apps, keep one clear owner of runtime lifecycle.
- Route
onErrorto application logging/telemetry. - Use
triode.freeze(),triode.step(), andtriode.resume()for deterministic live patching. - Use
triode.reset({ time, hooks, outputs, sources })for granular panic/reset flows.
Rehearse Polygon Rings
Open Polygon Rings. Use Alt+Enter to run the block under the cursor. A blank line separates each cue.
- In the drawing block, change the count in
draw("loop", 3, …)to5and run it. The same path now draws a pentagon. - Set the count to
100andharmonicto0.12. Run again to see the seventh harmonic reshape the ring. Change"loop"to"dots"and run once more. Dots also accept a rectangular field such as[50, 50]. - Add the mix and display as separate blocks. Run each to see the dots over noise.
noise(3).mult(0.25).add(src(o1)).out(o0);
render(o0);
- Add and run the trail block below. Change the mix input from
src(o1)tosrc(o2)and run the mix block. - Change the harmonic and run the drawing block. The old positions fade behind the new dots. Change the fade to
0.005, run the trail block, and move the drawing again for a longer trace.
trail(o1, { fade: 0.05 }).out(o2);
Use different outputs for the source drawing and trail history. A fade of 0 keeps previous marks and 1 clears them each frame. A callback such as () => 0.02 can set fade live. Its first samples must be finite numbers from 0 to 1 for the cue to publish. If the callback later fails, the trail keeps using its last valid fade and reports the error.