Randomness & determinism
Seeded Random, and the invariants that make scenes reproducible
Scenes are pure functions of (scene, settings). Run the same scene
twice — on your machine, in CI, in a viewer's browser — and you get the same
frame count and the same frame data. That's the property everything else
here is built on, and it survives randomness because randomness is seeded.
Seeded Random
Effect's Random service is provided to every scene, derived from the
seed setting (default: the string "effect-motion"):
const x = yield* Random.nextBetween(-780, 780);Same seed, same sequence — a "random" scene replays identically, which is
exactly what you want in a video. Different seed, different (equally
repeatable) outcome. What breaks the property is reaching outside the
scene: Math.random() and wall-clock reads have no place in a scene body.
The other invariants
- Exact landings. Duration-based animations put their final frame exactly on target; springs snap exactly on settle. No accumulation, no drift, no epsilon.
- The frame barrier. Concurrent animations advance one shared frame at a time, so concurrency never reorders results.
- Loud failures. An unknown easing name, an invalid spring, a scene-graph violation — each dies with a defect naming the offender, rather than producing subtly wrong frames.
- Determinism stops at the frame stream. Same seed and settings mean the same frames — the data. Rendered pixels are not byte-compared across GPUs and platforms; if two renders look the same, they are the same.
import { Random } from "effect";import * as Color from "effect-motion/Color";import * as Entity from "effect-motion/Entity";import * as Motion from "effect-motion/Motion";import * as Scene from "effect-motion/Scene";// Effect's Random is seeded per scene: every run of this walk — including// every replay in this player — visits exactly the same points. Change the// scene's `seed` setting and you get a different (equally repeatable) walk.export const scene = Scene.make( "seeded walk", function* () { const walker = yield* Scene.instantiate("Circle", { position: Entity.vec3({}), radius: 40, fillColor: Color.hex("#7f5af0"), }); for (let i = 0; i < 6; i++) { const x = yield* Random.nextBetween(-780, 780); const y = yield* Random.nextBetween(-380, 380); // a fading breadcrumb marks each visited point const crumb = yield* Scene.instantiate("Circle", { position: Entity.vec3({ x, y }), radius: 12, fillColor: Color.hex("#2cb67d"), opacity: 0, }); yield* Scene.all([ Motion.moveTo(walker, { x, y }, "500 millis", "easeInOutCubic"), Motion.fadeTo(crumb, 0.6, "500 millis"), ]); } yield* Motion.wait("600 millis"); }, { width: 1920, height: 1080, backgroundColor: Color.rgba(22, 22, 29) },);That's the core model. From here: the Guides for tasks, or the Examples to see it all composed.