add_code
Adds a sandboxed HTML, CSS and JS page as a layer for 3D, shaders, canvas, particle or GSAP animation that keyframes cannot express, driven by seek, adapter or clock.
Instructions
Add a code layer: a page you write (HTML, CSS, JavaScript) drawn into a box, for what keyframes cannot say: three.js and WebGL 3D, shaders, canvas, particles and physics, GSAP, Lottie, CSS animations. It runs in a sandboxed frame (no network to the project, no operations) and gets window.MOGA_CODE = { fps, width, height, seed, theme, colors: { "md.sys.color.primary": "#…", … }, t }. How it is driven (drive, default auto, picked from what the page offers): seek — set window.seek = (t) => { … } and draw time t (seconds from the layer start); any frame in any order, the fastest and the one to prefer, e.g. three.js: pose the scene for t and call renderer.render. adapter — no seek and no clock of its own: GSAP timelines, Lottie and CSS / Web Animations are seeked to t for you. clock — anything else (requestAnimationFrame loops, timers, Date, performance.now, stateful simulations): its clocks are virtual and step exactly one frame at a time, so frames are the same every run, but reaching a time means stepping there from the start (scrubbing back reloads the page). Math.random is seeded by seed in every mode. Load libraries from the project (import_file, then "/media/three.module.min.js" in an import or a script src) rather than the network. The layer is type "code" with props.html; change it later with set_props (html, start, drive, seed), set_motion and set_keyframe like any layer.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"composition": "<composition>"
},
"name": "add_code"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| h | No | Box height in px (default: the frame height) | |
| w | No | Box width in px (default: the frame width) | |
| x | No | Centre x in px (default: the frame centre) | |
| y | No | Centre y in px (default: the frame centre) | |
| id | No | Element id (default: "code") | |
| file | No | Or an .html file on disk (absolute, or relative to the project) whose text becomes html | |
| html | No | The page: markup, <style> and <script> (module scripts work) | |
| into | No | A composition nested inline in this one to put it in (default: this composition itself) | |
| seed | No | Seed for Math.random (default 1) | |
| basis | No | What you read and followed to make this change, as refs from search or lookup: rule:<lint or taste rule>, taste, feedback:<id> (earlier feedback this follows; what it answers goes in feedback), commit:<id> (an earlier change it builds on), asset:, template:, skill:… The person sees them under the change, so they know why it is this way. Name only what shaped it. | |
| drive | No | auto | |
| start | No | Seconds into the element where the page's time 0 falls (held on its first frame before) | |
| radius | No | Corner radius of the box in px | |
| message | No | One line saying why, kept with the change in the history | |
| feedback | No | Ids of the feedback this change answers (notes and marks from list_notes, list_examples or the conversation). When the person keeps the change it joins the record of that feedback, and when they then mark the feedback resolved it is the fix; when they take it back, the feedback opens again. | |
| confidence | No | How sure you are this change is what the person wants. high: they asked for exactly this, or you measured it against a reference. medium: you inferred it from the taste, a rule or earlier feedback. low: you are guessing, or it changes something they did not ask about. The person's threshold decides which changes stand by themselves and which wait for them to keep; say it honestly on every change. | |
| composition | Yes | Composition name (file in compositions/ without .json) |