A scene written as data
The pixel scenes on this site aren’t code. Each is a page of data: shapes, paints, bones and moves. Here is a small one. What does the engine ask of a description before it will play it?
Things to try
- Try nowTry now: Make the tree swayHint: The tree has a bone already. What makes a bone move?
- Up nextLater: Find the rule every move must keep
- Up nextLater: Light the lantern with a light that flickers
Starting the splat engine…
9 parts, 0 moves and 0 lights in 1.5 KB of text, cut into 0 blobs. It all comes round every 12 seconds.
0 of 3 goals done.
Description JSON: edit it
Checker what it says
Sound: nothing to say. The view shows it.
What you just saw
A scene is a description, checked, then compiled
A description says what is there, not how to draw it. Each part is a shape (a box, a ball, a roof, a cylinder) and a paint (a color, bricks, speckles, one paint on top and another on the sides). A part with no bone is land and stands still; a part on a bone goes where the bone goes. A bone does nothing until a move names it.
Before anything is cut, the checker reads the whole description and says what is wrong and where, as moves[0].times: must be a whole number. Then the compiler turns it into the shapes the grid is cut from, a poser that sets every bone from the time, and the live lights. Change a move or a light and only the pose changes; change a shape and the scene is cut again.
Every move fits a whole number of times into the loop, so at the end of the loop every bone is where it started and the scene runs for ever with no seam. That’s also why the same moment always looks the same, and why a loop can be recorded once and played as a picture. Because it is only text, a description can be checked before it runs, kept in a file, and written from a sentence.
Take it with you
This scene, as code
The last sound description in the box, played with the engine package. The description could as well be read from a .json file.
Install it with npm install @blobscape/engine three. Every shape, paint and move is in the guide to scene descriptions.
import { Stage, compileScene, checkScene, buildVoxels, type SceneDoc } from '@blobscape/engine'
// the whole scene is data: it could as well come from a .json file
const doc: SceneDoc = {
"name": "Cottage at dusk",
"loop": 12,
"light": { "from": [-0.5, 0.6, 0.6], "ambient": 0.45 },
"palette": ["#141a33", "#2a2f55", "#4a4f7a", "#2c4a2a", "#4a7a3a", "#7aa84e", "#4a3020", "#6e4a2e", "#a07850", "#d8c09a", "#8a2f2a", "#c0503a", "#ffd166", "#fff3b0"],
"sky": ["#141a33", "#c0503a"],
"look": { "dither": 0.1, "glow": 1.5, "outline": true, "edges": true },
"camera": { "target": [0, 0.45, 0], "distance": 3.6, "azimuth": 25, "elevation": 18 },
"bones": [{ "name": "tree", "at": [0.75, 0, -0.25] }],
"parts": [
{
"shape": { "kind": "cylinder", "at": [0, -0.2, 0], "height": 0.2, "r": 1.2 },
"paint": {
"kind": "faces",
"top": { "kind": "patches", "size": 0.3, "colors": ["#4a7a3a", "#7aa84e"] },
"side": "#6e4a2e"
}
},
{
"shape": { "kind": "box", "at": [-0.3, 0.25, 0], "half": [0.35, 0.25, 0.28] },
"paint": {
"kind": "bricks",
"size": [0.12, 0.06],
"colors": ["#d8c09a", "#a07850"],
"line": "#6e4a2e"
}
},
{
"shape": { "kind": "roof", "at": [-0.3, 0.5, 0], "half": [0.42, 0.34], "height": 0.3 },
"paint": "#8a2f2a"
},
{
"shape": { "kind": "box", "at": [-0.3, 0.14, 0.28], "half": [0.07, 0.14, 0.02] },
"paint": "#4a3020"
},
{
"shape": { "kind": "box", "at": [-0.08, 0.3, 0.28], "half": [0.06, 0.06, 0.02] },
"paint": "#ffd166",
"glow": true
},
{
"shape": { "kind": "cylinder", "at": [0.75, 0, -0.25], "height": 0.45, "r": 0.05 },
"paint": "#6e4a2e",
"bone": "tree"
},
{
"shape": { "kind": "ball", "at": [0.75, 0.62, -0.25], "r": [0.28, 0.3, 0.28] },
"paint": { "kind": "speckle", "size": 0.05, "colors": ["#2c4a2a", "#4a7a3a", "#7aa84e"] },
"bone": "tree"
},
{
"shape": { "kind": "cylinder", "at": [0.35, 0, 0.55], "height": 0.5, "r": 0.02 },
"paint": "#2a2f55"
},
{
"shape": { "kind": "box", "at": [0.35, 0.56, 0.55], "half": [0.045, 0.055, 0.045] },
"paint": "#ffd166",
"glow": true
}
]
}
// the checker says what is wrong, each as 'where: what'
const problems = checkScene(doc)
if (problems.length) throw new Error(problems.join('\n'))
// compiling gives the shapes for the builder, the poser, the lights and the pixel look
const scene = compileScene(doc)
const stage = await Stage.start(document.querySelector('canvas')!, { lights: true })
stage.setActor(buildVoxels(scene.spec(0.028)))
stage.orbit = scene.orbit
// a pose and the lights, from the time: everything comes round in scene.loop seconds
stage.setPoser((sk, t) => {
scene.pose(sk, t)
stage.setLights(scene.lights(t))
})