/* @jsxImportSource @diffusionstudio/jsx */ /* Declarative animation: useTicker exposes the playhead as reactive * accessors, createMemo derives values from it, and props consume the memos. * * cp examples/03-ticker.tsx ~/Projects/ticker/index.tsx * dapi open ~/Projects/ticker * * No timers, no imperative draw loop: each memo recomputes once per tick and * every consumer below reads the cached value. Press play; scrubbing works * too, and because the playhead is the only clock, exports and captures * render the exact same frames. */ import { createMemo } from "solid-js"; import { useTicker } from "@diffusionstudio/jsx"; const LOOP = 4; // seconds per revolution export default function Ticker() { const { time, frame } = useTicker(); // derived values: computed once per tick, shared by every consumer const progress = createMemo(() => (time() % LOOP) / LOOP); // 0..1 over the loop const angle = createMemo(() => progress() * Math.PI * 2); const hue = createMemo(() => Math.round(progress() * 360)); const eased = createMemo(() => 0.5 - Math.cos(angle()) / 2); // 0..1..0, smooth return ( {/* center square: rotation and corner radius both derive from progress */} {/* orbiting dot */} {/* loop progress bar */} t = {time().toFixed(2)}s / frame {frame()} / loop {Math.round(progress() * 100)}% ); }