Solids, cameras and paths

Solid layers draw lit 3D shapes as flat SVG paths, a camera layer moves through layers set at depths, and a path layer draws a line from one layer to the next. This page covers the solids stage, every shape, a solid's place and look, its sides and shadows, grain on a solid, bands and depth sorting, nulls and their controls, cameras, the 3D world, and paths.

Solid layers need a second file, kinetic.25d.js, loaded after kinetic.wf.js. The live examples on this site load kinetic.wf.js alone, so the solids examples below are complete code to copy into a page of your own. The frames with knobs load both files and run on the page: change a knob and the layer is drawn again. Cameras and paths need only kinetic.wf.js, and their examples run on the page.

A first solid

A solid is a shape kept as 3D numbers: a box, a prism, a sphere, or one of the flat shapes. At each frame Kinetic turns its corners, projects them onto the frame, and draws each face that looks toward you as an SVG path, lit by its angle to one light. The shapes stay sharp at any size, and nothing needs WebGL. The stage is the SVG element the solids draw into, with the view, the light and the rim they share. A layer of kind: 'solid' puts one shape on the stage.

Here a long box rolls half a turn about its length, like a log, over four seconds. Its faces darken as they turn from the light, a fine light line runs round each face, a pink sheen slides across them, and dark specks gather toward the edges.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Block</title>
    <script defer src="https://cdn.jsdelivr.net/npm/wildflowerjs@^1.5.5/dist/wildflower.lite.dev.js"></script>
    <script defer src="https://cdn.jsdelivr.net/npm/@wildflowerjs/kinetic@0.3/dist/kinetic.wf.js" data-preview></script>
    <script defer src="https://cdn.jsdelivr.net/npm/@wildflowerjs/kinetic@0.3/dist/kinetic.25d.js"></script>
    <script defer src="scene.js"></script>
    <style>
        html, body { margin: 0; }
        [data-composition-id] { position: relative; overflow: hidden; }
        [data-composition-id]:not([data-kinetic-ready]) { visibility: hidden; }
        .shot { position: absolute; inset: 0; }
        .shot svg, .shot canvas { position: absolute; left: 0; top: 0; width: 1280px; height: 720px; }
    </style>
</head>
<body>
    <div data-composition-id="main" data-start="0" data-duration="4"
         data-width="1280" data-height="720" data-fps="30">
        <div class="shot" data-component="block" data-start="0" data-duration="4">
            <svg viewBox="0 0 1280 720" aria-hidden="true">
                <rect width="1280" height="720" fill="#241a3a"/>
                <g class="solids"></g>
            </svg>
            <canvas class="grain" width="1280" height="720"></canvas>
        </div>
    </div>
</body>
</html>

The page loads three files from Kinetic's package: the framework, kinetic.wf.js, and kinetic.25d.js after it. The clip holds an <svg> with an empty <g class="solids">, where the shapes are drawn, and a <canvas> over it, where their grain is drawn. scene.js holds the layers.

wildflower.kinetic.layers.scene('block', {
    stage: {
        src: '.solids',
        grain: '.grain',
        view: { distance: 6, focal: 1100 },
        light: { dir: [-0.4, 0.5, 0.8], ramp: ['#241a3a', '#6b3a6e', '#e0735c', '#ffd9a8'] },
        rim: { color: '#ffe9cc', width: 1.5 },
        glows: [{ dir: [0.8, 0.3, 0.5], color: '#ff9ad5' }],
    },
    looks: { dots: { kind: 'stipple', scale: 1.5 } },
    layers: [
        {
            id: 'block', kind: 'solid',
            content: { shape: 'box', size: [1.6, 1, 1] },
            place: { rotate: [{ at: [0, 4], to: [0, 180], ease: 'sine.inOut' }, 30, 0] },
            look: { shade: [{ look: 'dots', marks: [{ edge: { width: 0.18 }, ink: '#241a3a', amount: 0.7 }] }] },
        },
    ],
});
  • stage says where the solids draw and how they are lit (The stage).
  • content gives the shape and its numbers: a box 1.6 units long and 1 unit high and deep (The shapes).
  • place.rotate turns it 180 degrees about its own x axis, its length, over the four seconds, and a fixed turn of 30 degrees about y swings one end toward you so its end face shows (Placing a solid).
  • look.shade lays specks along each face's edges in the dark ink, drawn in the dots look on the grain canvas (Grain on a solid).

A solid's units are the stage's own, not pixels. With the view above, the eye sits 6 units in front of the middle of the frame, and one unit at a distance of 1 is 1100 px across, so the box's middle, at a distance of 6, is about 180 px a unit.

The stage

The top-level stage key sets up the stage, once, when the layers are built. A track written inside it is read at time 0 and does not move.

stage: { src: '.solids' }

src is a selector for the SVG element the shapes draw into, looked for in the clip first and then in the whole composition. A <g> inside the clip's <svg> lets the backdrop sit under the shapes in the same <svg>. Without src, the shapes draw into the clip's first <svg>.

stage: { src: '.solids', grain: '.grain' }

grain is a selector for the <canvas> that the shapes' grain is drawn on. Lay the canvas over the <svg> at the same size. A scene needs it only when a solid has a look.shade.

stage: { view: { distance: 5, focal: 900, roll: 45, near: 0.2, fade: 1.4 } }

view places the eye. The eye sits distance units in front of the stage's middle and looks into the frame, with y up on screen. focal is how many pixels one unit spans at a distance of 1, so a larger focal draws everything larger. roll turns the whole frame about its middle, in degrees, so at 45 a square face shows as a diamond. A face closer than near units to the eye is cut off there, and with fade above 0 it thins out over that many units before it gets there, so a shape that flies past the eye fades instead of filling the frame. center moves the frame's middle, in the SVG's units.

Without view, the eye is far off, so the solids look nearly flat, and the frame is one unit across: on a 1280 px frame, a disc of radius 0.06 has a radius of about 77 px. That suits flat pieces made of discs, slices and plates.

stage: { light: { dir: [-0.35, 0.45, 0.85], ramp: ['#101826', '#1f4f7a', '#5fb3d9', '#e8f7ff'] } }

light is the one light. dir points toward it, here up, to the left, and toward you. A face turned toward the light takes a color from the lit end of ramp, and one turned away takes a color from the dark end, so list the ramp from dark to lit. gamma, floor, gain, bounce and across shape how the tone falls off (solids() options).

stage: { rim: { color: '#e8f7ff', width: 1.5 } }

rim draws a fine line round each face that brightens as the face turns edge-on. A stage without rim, or with rim: false, draws no lines.

A prism and a box turning side by side. A shorter distance makes the near faces swell against the far ones, and a larger focal draws everything larger. The light knobs move where the bright faces are. Click to pause.
stage: { glows: [{ dir: [0.8, 0.3, 0.5], color: '#ff9ad5', bleed: {} }] }

Each glow is a soft patch of color where a light at dir would reflect off a face into the eye. It slides across the face as the face turns. bleed draws it again, larger and fainter, past the face's edge. gradient names a <radialGradient> of the page's own in place of color.

stage: { dropShadow: { blur: 22, color: '#404860', opacity: 0.8, offset: [18, 24] } }

dropShadow makes each solid cast a soft shadow on the solids behind it. The shadow is the solid's outline, blurred by blur px, moved by offset px, and laid over what it falls on in color, opacity strong. Left out, blur is 24, color is black, opacity is 0.35 and there is no offset. color can be a swatch's or a role's name. A solid's look.casts and look.accepts say which shadows fall where (Shadows).

The shapes

content.shape picks the shape, and the rest of content gives its numbers, in the stage's units. Every shape is centered on its own middle. The flat shapes lie in the plane of the frame, facing you, until a turn tips them.

Each shape with the numbers given below, swinging either way about y. Tilt turns it about x. Click to pause.
{ id: 'card', kind: 'solid', content: { shape: 'plane', size: [1, 0.6] } }

A flat rectangle 1 unit wide and 0.6 high. size: 1 is a square.

{ id: 'coin', kind: 'solid', content: { shape: 'disc', radius: 0.5 } }

A flat circle of radius 0.5.

{ id: 'pie', kind: 'solid', content: { shape: 'sector', radius: 0.5, from: 0, to: 270 } }

A flat slice of a circle, from from to to in degrees, measured clockwise from straight up. This one is three quarters of a disc with the top-left quarter missing. Give from and to every time.

{ id: 'ring', kind: 'solid', content: { shape: 'sector', radius: 0.5, inner: 0.3, from: 0, to: 360 } }

With inner, only the part outside that radius is drawn, so a whole turn is a ring 0.2 units thick.

{ id: 'drop', kind: 'solid', content: { shape: 'capsule', radius: [0.3, 0.15], length: 0.6 } }

Two circles length apart along x, joined by the straight lines that touch both. With one radius it is a pill; with two, [left, right], it narrows from a round end of 0.3 to one of 0.15, like a drop on its side.

{ id: 'brick', kind: 'solid', content: { shape: 'box', size: [1, 0.6, 0.6] } }

A solid box 1 unit long and 0.6 high and deep. size: 1 is a cube.

{ id: 'tri', kind: 'solid', content: { shape: 'faces', faces: [{ pts: [[-0.5, -0.4, 0], [0.5, -0.4, 0], [0, 0.5, 0]] }] } }

Faces of your own: each one three or more corners [x, y, z], here a single triangle. A face's outward direction comes from its first three corners in order, or from n, such as n: [0, 0, 1]. A face that turns away from the eye is not drawn, so list each face's corners counterclockwise as seen from outside the solid.

{ id: 'hex', kind: 'solid', content: { shape: 'polygon', sides: 6, radius: 0.5 } }

A flat regular hexagon whose corners lie 0.5 from its middle, its first corner straight up.

{ id: 'nut', kind: 'solid', content: { shape: 'prism', sides: 6, radius: 0.4, depth: 0.6, taper: 0.5 } }

A hexagon carried back 0.6 units into the frame, its back half the size of its front, so it looks like a nut that narrows away from you. taper is 1 when left out, a straight prism, and taper: 0 brings the back to a point.

{ id: 'peak', kind: 'solid', content: { shape: 'pyramid', sides: 4, radius: 0.5, height: 0.8 } }

A pyramid 0.8 units tall standing on a square base, with a corner of the base toward you.

{ id: 'ball', kind: 'solid', content: { shape: 'sphere', radius: 0.5 } }

A ball, drawn from its outline at each frame and shaded brighter on the side toward the light. wedges (with an axis around, 'x', 'y' or 'z') and bands (along an axis along) divide it into parts. Each part takes a color of its own from look.side (Sides).

The numbers of a sector, a capsule, a polygon, a prism, a pyramid and a sphere can move: write a track as any of them and the shape is made again whenever its numbers change. A plane, a disc and a box keep the numbers they have at time 0, so change their size with place.scale. A list of faces written out is also read once; a list a value form gives moves (below).

{ id: 'sail', kind: 'solid', content: { shape: 'faces', faces: { call: 'sail', args: [{ rate: 1 }] } } }
// handed over in fns:
sail: (t) => (t >= 3 ? [] : [{ pts: [[-0.5, -0.4, 0], [0.5, -0.4, 0], [0, -0.4 + 0.3 * t, 0]], n: [0, 0, 1] }])

When faces is a value form, a call, a link or a track, the list is read at every frame, and the shape is made again whenever it changes. This triangle's tip rises for three seconds, and then the list is empty, which draws nothing for the layer.

{ id: 'pie', kind: 'solid', content: { shape: 'sector', radius: 0.08, from: 0, to: { at: [0, 3], to: [0, 360] } } }

A slice that grows clockwise from straight up into a whole disc over three seconds, like a timer filling.

{ id: 'pill', kind: 'solid', content: { shape: 'capsule', radius: 0.04, length: { at: [0, 3], to: [0, 0.2] } } }

A dot that stretches sideways into a pill, from both ends at once.

Placing a solid

A solid's place takes position, rotate, scale and pivot, all in the stage's units. On the stage, x runs right, y runs up, and z runs toward you.

place: { position: [-1.2, 0.5, 0] }

Moves the shape 1.2 units left and 0.5 up from the stage's middle.

place: { rotate: [25, 35, { at: [0, 4], to: [0, 360] }] }

Turns the shape in degrees about its own x axis, then y, then z. Here it is turned 25 degrees about x and 35 about y, and spins once about z over four seconds. A positive turn about z is counterclockwise on screen.

place: { scale: [{ at: [0, 2], to: [1, 2] }, 1, 0.5] }

A number scales the shape evenly; [x, y, z] stretches it along each axis. This box doubles in length over two seconds while it stays half as deep.

{ id: 'door', kind: 'solid', content: { shape: 'plane', size: [1, 0.6] },
  place: { position: [-1.2, 0, 0], pivot: [-0.5, 0, 0], rotate: [0, 0, { at: [0, 2], to: [0, 60] }] } }

pivot is the point of the shape's own space that position puts in place and that it turns and scales about. Here the pivot is the middle of the plate's left edge, so that point stays at 1.2 units left of the middle while the plate swings 60 degrees counterclockwise about it.

A solid's look

look: { opacity: { at: [0, 0.5], to: [0, 1] } }

Fades the shape in over half a second. Outside its life, a solid is not drawn.

swatches: { coral: '#ff6f59' },
layers: [{ id: 'dot', kind: 'solid', content: { shape: 'disc', radius: 0.06 }, look: { color: 'coral' } }]

One color, given by a swatch's name, a role's name or a #rrggbb value, paints the shape flat, with no light on it. This is the look for flat graphics made of discs and slices.

look: { color: ['#1d2b53', '#ff6f59', '#fff1d6'] }

A list of two or more #rrggbb colors is the shape's own ramp, dark to lit, read through the stage's light in place of the stage's ramp. This box is navy on the faces turned from the light, coral in between, and cream on the lit faces.

look: { color: { keys: [[0, ['hold', 'coral']], [2, ['hold', 'sun']]] } }

A color can change over time: this one is coral, then sun from 2 seconds on.

look: { color: { gradient: ['#1d2b53', 'coral', '#fff1d6'], angle: 90 } }

A gradient paints the shape from one color to the next along a line in the shape's own space, so it moves and turns with the shape, with no light on it. angle is in degrees counterclockwise from the shape's x axis, 0 when left out, so this one runs from navy at the bottom through coral to cream at the top. Each stop is a color, spaced evenly by its place in the list, or [offset, color] with the offset from 0 to 1. A stop's color is #rrggbb, #rrggbbaa for one that is partly clear, or a swatch's or a role's name that gives one. from: [x, y] and to: [x, y], two points in the shape's own units, set the line's ends in place of angle. The angle, the offsets and the colors can each be a track.

look: { color: ['#1d2b53', '#ff6f59', '#fff1d6'], albedo: 0.4 }

albedo is how much light the shape gives back, 1 when left out, so at 0.4 the same box reads darker all round. glow scales how strongly the stage's glows show on it in the same way. Both are read once, at time 0.

A box with each kind of color, and its top colored on its own with side.top. A ramp is lit by the light; one color and a gradient are not, so albedo changes only a ramp. Click to pause.
{ id: 'window', kind: 'solid', hidden: true, content: { shape: 'sector', radius: 0.1, from: 90, to: 270 },
  place: { position: [0.3, 0.1, 0] } },
{ id: 'half', kind: 'solid', content: { shape: 'disc', radius: 0.08 }, place: { position: [0.3, 0.1, 0] },
  look: { color: 'sun', clip: 'window' } }

look.clip draws the shape only inside another layer's outline. hidden: true keeps that other layer from drawing, so it serves only as the outline. The slice runs clockwise from 90 to 270 degrees, through the bottom, so only the disc's lower half shows.

look: { color: 'sun', clip: { layer: 'window', invert: true } }

Written as { layer, invert: true }, the clip keeps the shape outside the other layer's outline instead, so the same disc shows only its upper half. { layer: 'window' } alone is the same as clip: 'window'.

The yellow disc drawn through a hidden slice that turns once every six seconds, with the whole disc faint under it. From and to set the slice; invert keeps the disc outside it instead. Click to pause.

Sides

{ id: 'crate', kind: 'solid', content: { shape: 'box', size: 0.8 },
  look: { color: ['#1d2b53', '#ff6f59', '#fff1d6'], side: { top: '#ffc145', front: ['#3b1f0e', '#c98a3c', '#ffe2a8'] } } }

look.side colors a shape's sides one by one, over its look.color. It is an object of the sides by name: a box's are front, back, left, right, top and bottom; a prism's front, back and side; a pyramid's base and side; a flat shape's front and back; and a list of faces' the names its faces give in side. Each side takes what look.color takes: a color, a ramp, a gradient or a track. A track that holds null takes the color off from there: a side goes back to its shape's color, and a shape to the stage's ramp. Here the top is a flat yellow and the front has a brown ramp of its own, lit by the light, while the other sides keep the box's ramp. A flat shape shows its back only when side.back has a color.

{ id: 'ball', kind: 'solid', content: { shape: 'sphere', radius: 0.5, wedges: 4 },
  look: { side: ['#ff6f59', '#ffc145', null, { keys: [[0, '#ff6f59'], [2, '#ffc145']] }] } }

A sphere's parts are numbered, so its side is a list with one entry for each wedge or band, in order, and null leaves a part in the shape's own color. Wedge 0 faces you, and band 0 is at the far end of its axis. The last wedge here turns from coral to yellow over two seconds.

side: { top: { color: '#ffc145', shade: [{ look: 'dots', marks: [{ edge: { width: 0.1 }, ink: '#241a3a' }] }] } }

A side written as { color, shade } also takes grain of its own (Grain on a solid).

Shadows

{ id: 'wall', kind: 'solid', content: { shape: 'plane', size: 6 }, place: { position: [0, 0, -1] }, look: { casts: 0 } },
{ id: 'label', kind: 'solid', content: { shape: 'plane', size: [0.6, 0.2] }, look: { accepts: false } }

With the stage's dropShadow on, every solid casts a shadow at full strength on the solids behind it. look.casts sets how strong a shadow the solid casts, from 0 to 1, and can change over time; at 0 it casts none, which suits a wall behind everything. look.accepts: false keeps every shadow off the solid, such as a label that should stay clean; it is read once, at time 0.

The shadow is a flat graphic effect, like a drop shadow under a layer: the solid's outline, moved by the stage's offset and blurred. The stage's light has no part in it, and it keeps the same size and softness however far the solid is from what it falls on. Each face holds a blurred copy of every outline that can fall on it, so a stage of many solids plays slowly in the page with the shadow on. A render waits for each frame, so its file is the same either way. For shadows a light casts, which grow and soften with distance, use a three.js scene in Trillium.

A box turning in front of a wall that casts nothing. Blur, opacity and offset shape the stage's shadow, casts scales the box's, and accepts turned off keeps it off the wall. Click to pause.

Grain on a solid

look.shade lays specks or soft color over a solid, drawn on the stage's grain canvas. It is a list of groups, each { look, marks }. look names one of the top-level looks, which say how the specks are drawn, with the options that shade() takes (kind, scale, speck, opacity, blend), and travel: false to keep the specks still on the frame while the shape moves. marks say where the ink goes, in the shape's own units.

looks: { dots: { kind: 'stipple', scale: 1.5 } },
layers: [{
    id: 'block', kind: 'solid', content: { shape: 'box', size: [1.6, 1, 1] },
    look: { shade: [{ look: 'dots', marks: [{ edge: { width: 0.18 }, ink: '#241a3a', amount: 0.7 }] }] },
}]

An edge mark lays ink inward from each face's outline, width units deep, as in the first example.

marks: [{ glow: { at: [0.03, -0.03], radius: 0.1, invert: true }, ink: 'shadow', amount: 0.9 }]

A glow mark spreads ink from a point out to radius. With invert: true the ink is thinnest at the point and thickest at the radius, so a disc with this mark is clean toward its lower right and dark round the rest of its edge, like a lit ball. Each mark also takes falloff, a curve's name from curves or an ease, and within: { point, radius }, which keeps it inside a circle.

A comp can name groups and marks once and use them by name. In a comp, looks holds lists of groups and marks holds single marks.

comps: {
    badge: {
        looks: { shaded: [{ look: 'dots', marks: ['inner'] }] },
        marks: { inner: { glow: { at: [0.03, -0.03], radius: 0.1, invert: true }, ink: 'shadow', amount: 0.9 } },
        layers: [
            { id: 'face', kind: 'solid', content: { shape: 'disc', radius: 0.08 }, look: { color: 'coral', shade: 'shaded' } },
        ],
    },
},

shade: 'shaded' reads the comp's list, and 'inner' in it reads the comp's mark. A role can name the list too, so each placement of the comp picks its own (Comps and copies). shade: { role: 'finish', mirror: 'y' } reads the list the role finish gives and flips its marks top to bottom, so the clean spot of the badge above moves to its upper right.

Bands and depth sorting

Without bands, the stage sorts every face of every solid by its distance from the eye and draws the far ones first. A solid wholly in front of a face, such as a box in front of a wall or standing on a floor, draws after that face wherever it stands. Shapes that pass in front of each other then draw as they stand in 3D. Here two boxes circle a point between them, each turning about it with place.pivot, so halfway round the coral box passes in front of the blue one.

wildflower.kinetic.layers.scene('nest', {
    stage: {
        src: '.solids',
        view: { distance: 5, focal: 700, roll: 45 },
        light: { dir: [-0.35, 0.45, 0.85], ramp: ['#101826', '#1f4f7a', '#5fb3d9', '#e8f7ff'] },
        rim: { color: '#e8f7ff', width: 1.5 },
    },
    layers: [
        { id: 'left', kind: 'solid', content: { shape: 'box', size: 0.8 },
          place: { pivot: [0.7, 0, 0], rotate: [0, { at: [0, 3], to: [0, 180], ease: 'power3.inOut' }, 0] },
          look: { color: ['#1d2b53', '#ff6f59', '#fff1d6'] } },
        { id: 'right', kind: 'solid', content: { shape: 'box', size: 0.8 },
          place: { pivot: [-0.7, 0, 0], rotate: [0, { at: [0, 3], to: [0, 180], ease: 'power3.inOut' }, 0] } },
    ],
});

The page is the first example's, with data-component="nest", a 3-second clip, and a backdrop of #101826.

bands lists named layers of drawing from the bottom up, and each solid's band picks one. Each band then draws over the bands before it, whatever the depths. Add these three lines to the scene above:

bands: ['left', 'right'],
// on the left layer:
band: 'left',
// on the right layer:
band: 'right',

Now the blue box draws over the coral one the whole way round, even halfway, when it is the farther of the two. Use bands for flat pieces whose order you choose, such as discs stacked on a slice, where depth says nothing about which one belongs on top. Use depth sorting for shapes that really move round each other in 3D.

  • Within a band, solids draw in the order they are listed. Among copies of a comp, a copy that started later draws over one that started earlier.
  • band can change over time, as a { keys } track of held names: band: { keys: [[0, ['hold', 'back']], [1.5, ['hold', 'front']]] } moves a solid from the back band to the front one at 1.5 seconds.
  • A band that is not in bands is KN-167.
  • Faces that cut through each other can sort wrong, since each face is drawn whole. Solids that pass through each other, or curved surfaces lit in detail, need Trillium.

Nulls and controls

A layer of kind: 'null' is a solid with nothing to draw. A solid with parent set to the null moves, turns and scales with it, so one turn of the null swings every child at once. A null's controls are named values that other layers read with a link, { from: 'nullId.name' }.

wildflower.kinetic.layers.scene('spinner', {
    swatches: { ink: '#1d2b53', coral: '#ff6f59', sun: '#ffc145' },
    layers: [
        { id: 'arm', kind: 'null',
          controls: { turn: { at: [0, 4], to: [0, 360], ease: 'power2.inOut' } },
          place: { rotate: [0, 0, { from: 'arm.turn' }] } },
        { id: 'left', kind: 'solid', parent: 'arm', content: { shape: 'disc', radius: 0.06 },
          place: { position: [-0.2, 0, 0] }, look: { color: 'coral' } },
        { id: 'right', kind: 'solid', parent: 'arm', content: { shape: 'disc', radius: 0.06 },
          place: { position: [0.2, 0, 0] }, look: { color: 'sun' } },
        { id: 'hub', kind: 'solid', content: { shape: 'polygon', sides: 3, radius: 0.05 },
          place: { rotate: [0, 0, { from: 'arm.turn', scale: -2 }] }, look: { color: 'ink' } },
    ],
});

The page is the first example's, with data-component="spinner" and a backdrop of #f3ede2, and the scene has no stage key, so the frame is one unit across and the shapes are flat colors. A coral disc and a yellow one sit on either side of the middle, and the arm carries them once round counterclockwise. The navy triangle in the middle reads the same turn and spins the other way, twice as fast.

  • A child's position is in its parent's space, so the discs stay 0.2 units from the middle as the arm turns.
  • A comp layer with parent puts every solid in that comp under the parent: { id: 'left', kind: 'comp', comp: 'bead', parent: 'arm', params: { x: -0.2 } }.
  • A solid in such a comp with parent: null stays on the stage itself and does not move with the arm.
  • A null takes only parent, place and controls, besides id, kind and life.

Cameras

A camera layer moves the composition's world, an element with the class world, as a camera moving through it would. Layers inside the world sit at depths, so the near ones slide past faster than the far ones. Here the camera starts pulled back and to the right of three cards, then pushes in and centers over three seconds, and its focus moves from the far card to the near one.

<div data-composition-id="main" data-start="0" data-duration="5"
     data-width="1280" data-height="720" data-fps="30">
    <div class="shot" data-component="flight" data-start="0" data-duration="5">
        <div class="world">
            <div class="card far">Far</div>
            <div class="card middle">Middle</div>
            <div class="card near">Near</div>
        </div>
    </div>
</div>
wildflower.kinetic.layers.scene('flight', {
    layers: [
        {
            id: 'cam', kind: 'camera', perspective: 1000,
            moves: [
                { to: { x: 240, y: -60, z: -400 } },
                { t: 0.5, d: 3, to: { x: 0, y: 0, z: 380 }, ease: 'power2.inOut', lag: { x: 0.4 } },
            ],
            focus: { at: [0.5, 3.5], to: [-1400, 0] },
        },
        { id: 'far', kind: 'html', src: '.far', band: 'world', size: [520, 300],
          place: { position: [-520, -200, -1400] }, look: { blur: { focus: { depth: 150, max: 10 } } } },
        { id: 'middle', kind: 'html', src: '.middle', band: 'world', size: [420, 260],
          place: { position: [420, 170, -700] }, look: { blur: { focus: { depth: 150, max: 10 } } } },
        { id: 'near', kind: 'html', src: '.near', band: 'world', size: [360, 220],
          place: { position: [-120, 40, 0] }, look: { blur: { focus: { depth: 150, max: 10 } } } },
    ],
});
html, body { margin: 0; }
[data-composition-id] {
    position: relative;
    overflow: hidden;
    background: #10162b;
    color: #fff;
    font-family: system-ui, sans-serif;
}
[data-composition-id]:not([data-kinetic-ready]) { visibility: hidden; }
.shot, .world { position: absolute; inset: 0; }
.card {
    position: absolute;
    left: 50%;
    top: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 24px;
    font-size: 64px;
    font-weight: 700;
}
.far { background: #3b4a8f; }
.middle { background: #c2577a; }
.near { background: #f2b34c; color: #10162b; }
A push through three cards

A camera layer takes perspective, moves and focus, and life like any layer.

{ id: 'cam', kind: 'camera', perspective: 1000, moves: [{ to: { x: 240, y: -60, z: -400 } }] }

perspective is the eye's distance in px from the plane z = 0, 1000 when left out. moves is the list that moves() takes. Its first entry is where the camera starts: here 240 px right, 60 px up (y runs down, as in CSS) and 400 px back, so the scene starts small and off to the left.

{ t: 0.5, d: 3, to: { x: 0, y: 0, z: 380 }, ease: 'power2.inOut', lag: { x: 0.4 } }

Each entry after the first is a move: from t for d seconds toward to. A positive z moves the camera into the scene. lag: { x: 0.4 } starts the sideways part 0.4 seconds after the push, so the camera's path curves.

focus: { at: [0.5, 3.5], to: [-1400, 0] }

focus is the depth of the plane in focus, here moving from the far card's depth to the near card's. A layer reads its blur from it with { focus: { depth, max } }: sharp within depth px of that plane, and up to max px of blur away from it (Values).

A camera's times and places take names as well as numbers.

{ id: 'close', kind: 'camera', life: [2.5, 5], perspective: 1000,
  moves: [
      { t: 2.5, to: { x: 420, y: 170, z: { distance: 900, from: 'middle' } } },
      { t: 2.5, d: 2, to: { z: { distance: 300, from: 'middle' } }, dolly: 'middle' },
  ] }
  • t and d take a marker's name or a sum such as 'hit1 - beat 1', like any time (Values).
  • z: { distance: 900, from: 'middle' } puts the camera 900 px in front of the plane of the layer middle.
  • dolly: 'middle' moves z at a steady rate of zoom toward that layer's plane, so the push does not seem to speed up as it nears.
  • With several cameras, the scene uses the last one listed whose life includes the current time. Added to the example above, this camera cuts to the middle card at 2.5 seconds, 900 px in front of it, and closes to 300 px.

The world

The world is the element with the class world in the composition, normally the size of the stage. A scene that has a camera sets the world's transform, and a scene with no camera leaves it alone, so one camera can serve several scenes. An opacity, filter or clip-path on the world flattens its layers, so put those on the layers inside it.

{ id: 'far', kind: 'html', src: '.far', band: 'world', size: [520, 300], place: { position: [-520, -200, -1400] } }

An HTML layer with band: 'world' stands in the world. size sets the element's width and height in px, and place.position puts its center at [x, y, z] px from the world's middle, with z toward you. Give the element position: absolute; left: 50%; top: 50% in the CSS, as the cards above have. A world layer is hidden once the camera passes its plane. Of look it takes opacity, blur and style, and while it is hidden it holds none of its style.

A world layer measures itself for links to read. 'self.cameraDistance' is its distance in px from the camera, and 'self.screenScale' is the perspective divided by that distance, the factor by which the camera enlarges it.

look: { opacity: { by: 'self.cameraDistance', keys: [[200, 0], [600, 1]] } }

Fades the layer out over the last 400 px before the camera reaches it.

{ id: 'board', kind: 'html', src: '.board', band: 'world', group: true },
{ id: 'cardA', kind: 'html', parent: 'board', src: '#cardA', size: [480, 300],
  place: { position: [-300, 0, -300], rotate: [0, 35, 0] } }

A group is a world layer with group: true that holds other layers. Each child names the group as its parent, sits at its position from the world's middle, and turns about its own center by the x and y of place.rotate, in degrees, so cards can stand at angles to each other. Put the children's elements inside the group's element, give the group transform-style: preserve-3d, and give each child position: absolute; Kinetic sets their left, top and transform. A path runs inside a group.

Paths

A path layer draws one line through several layers in a group. It starts at a point on one layer, runs along an SVG path on each card in turn, and crosses the gaps between cards as straight ribbons. Its look.trim.end says how far along the line is drawn at each moment, and a camera can ride the line's head. Here a line leaves a dot on the left, runs across one card, jumps to a second card further back, and runs across that one, while the camera follows it; a yellow dot pops up as the line reaches the end.

<div data-composition-id="main" data-start="0" data-duration="5"
     data-width="1280" data-height="720" data-fps="30">
    <div class="shot" data-component="route" data-start="0" data-duration="5">
        <div class="world">
            <div class="board">
                <div class="link" id="link0"></div>
                <div class="link" id="link1"></div>
                <div class="start"><i class="dot"></i></div>
                <div class="card" id="cardA">
                    <svg viewBox="0 0 480 300" width="480" height="300">
                        <path class="route" id="routeA" d="M40 250 L200 80 L300 200 L440 60"
                              pathLength="1" stroke-dasharray="1 1" stroke-dashoffset="1"/>
                    </svg>
                </div>
                <div class="card" id="cardB">
                    <svg viewBox="0 0 480 300" width="480" height="300">
                        <path class="route" id="routeB" d="M40 60 L180 240 L320 120 L440 250"
                              pathLength="1" stroke-dasharray="1 1" stroke-dashoffset="1"/>
                        <g transform="translate(440 250)"><circle id="goal" r="22"/></g>
                    </svg>
                </div>
            </div>
        </div>
    </div>
</div>
wildflower.kinetic.layers.scene('route', {
    layers: [
        {
            id: 'cam', kind: 'camera', perspective: 1000,
            moves: [
                { to: { z: -500 } },
                { t: 0.3, d: 4.4, to: { behavior: 'ride', path: 'line', distance: 900, reach: 500 } },
            ],
        },
        { id: 'board', kind: 'html', src: '.board', band: 'world', group: true },
        { id: 'start', kind: 'html', parent: 'board', src: '.start', size: [40, 40], place: { position: [-760, 120, 0] } },
        { id: 'cardA', kind: 'html', parent: 'board', src: '#cardA', size: [480, 300],
          place: { position: [-300, 0, -300], rotate: [0, 35, 0] } },
        { id: 'cardB', kind: 'html', parent: 'board', src: '#cardB', size: [480, 300],
          place: { position: [420, 40, -700], rotate: [0, -35, 0] } },
        {
            id: 'line', kind: 'path', parent: 'board',
            content: {
                points: [
                    { on: 'start', at: '.dot' },
                    { on: 'cardA', path: '#routeA', stop: 'A' },
                    { on: 'cardB', path: '#routeB', stop: 'B' },
                ],
                between: ['#link0', '#link1'],
            },
            look: { trim: { end: { keys: [[0.3, 'start'], [1.2, 'A.start'], [2.4, 'A.end'], [3.2, 'B.start'], [4.4, 'B.end']], ease: 'smooth' } } },
        },
        { id: 'goal', kind: 'svg', src: '#goal', place: { scale: { by: 'line.B', keys: [[0.9, 0], [1, 1]], ease: 'back.out' } } },
    ],
});
html, body { margin: 0; }
[data-composition-id] {
    position: relative;
    overflow: hidden;
    background: #14182e;
    font-family: system-ui, sans-serif;
}
[data-composition-id]:not([data-kinetic-ready]) { visibility: hidden; }
.shot, .world { position: absolute; inset: 0; }
.board { position: absolute; left: 0; top: 0; width: 100%; height: 100%; transform-style: preserve-3d; }
.card { position: absolute; border-radius: 20px; background: #2c3566; }
.card svg { position: absolute; inset: 0; }
#goal { fill: #f2b34c; }
.route { fill: none; stroke: #7cf0c5; stroke-width: 10; stroke-linecap: round; stroke-linejoin: round; }
.start { position: absolute; }
.dot { position: absolute; left: 10px; top: 10px; width: 20px; height: 20px; border-radius: 50%; background: #7cf0c5; }
.link { position: absolute; left: 0; top: 0; height: 10px; transform-origin: 0 50%; background: #7cf0c5; visibility: hidden; }
A line across two cards

A path layer takes content.points, content.between, content.head and look.trim.end, and its parent is the group it runs in.

points: [
    { on: 'start', at: '.dot' },
    { on: 'cardA', path: '#routeA', stop: 'A' },
    { on: 'cardB', path: '#routeB', stop: 'B' },
]

The first point is always the center of an element (at) inside a layer (on), where the line starts. Each point after it is a stop: an SVG <path> (path) inside a layer, which the line follows from its first corner to its last, carried into the world as the layer is placed and turned. Write each stop's d as straight lines, M x y L x y ..., and give the path pathLength="1" stroke-dasharray="1 1" stroke-dashoffset="1", so Kinetic can draw it on by its dash offset. stop names the stop for the trim and for links.

between: ['#link0', '#link1']

One selector for each straight stretch between stops, here from the dot to card A and from card A to card B. Each element is laid along its stretch in 3D and drawn on from its start by scaling it along its length. Style it as a thin bar with transform-origin: 0 50% and visibility: hidden; Kinetic sets its place, length and visibility.

look: { trim: { end: { keys: [[0.3, 'start'], [1.2, 'A.start'], [2.4, 'A.end'], [3.2, 'B.start'], [4.4, 'B.end']], ease: 'smooth' } } }

trim.end is a { keys } track of how far along the line the drawing reaches. A key's value is a distance in px along the line, or a stop's name: 'start' is the first point, and 'A.start' and 'A.end' are where stop A begins and ends. Here the line reaches card A at 1.2 seconds, crosses it by 2.4, and finishes card B at 4.4.

head: { el: '#tip', grow: [400, 16] }

content.head is a disc that rides the end of the line between stops, turned to face the camera. It starts the size of the first point's element and grows to a radius of grow[1] px over the first grow[0] px of line. A stop can carry a head of its own, head: '#tipA', an SVG circle on that card that rides the line's end while the line crosses the card.

{ id: 'goal', kind: 'svg', src: '#goal', place: { scale: { by: 'line.B', keys: [[0.9, 0], [1, 1]], ease: 'back.out' } } }

Other layers read the path's progress with links. 'line.B' is how far the line has got along stop B, from 0 to 1, so the yellow dot pops up over the last tenth of card B. 'line.head' is the distance in px the line has reached.

{ t: 0.3, d: 4.4, to: { behavior: 'ride', path: 'line', distance: 900, reach: 500 } }

A camera move with behavior: 'ride' follows the end of the line on the path layer path, about distance px away from it, and turns to face each card as the line comes within about reach px of it. wander adds a slow sway, and until, a time, stops the ride where the line is at that time. then: { at: [from, to], eye, look, ease, push } hands over from the ride to a shot from the point eye toward the point look between those two times, and pushes in push px a second from from on.

Errors

  • A stage key that is not src, grain, view, light, rim, glows or dropShadow is KN-162, and so is a shape name that is not one of the shapes, or a content key a solid does not take.
  • A look.side name that is not one of the shape's sides, a sphere's side that is not a list or has more entries than parts, a side key other than color and shade, a gradient key other than gradient, angle, from and to, and a look.clip key other than layer and invert are KN-162 (a clip's layer that is not there is KN-164), and so is look.side, look.casts or look.accepts on a layer that is not a solid.
  • A gradient with fewer than two stops, a stop that is not #rrggbb or #rrggbbaa or a name that gives one, and a look.accepts that is not true or false are KN-165.
  • A stage.src or stage.grain that finds no element is KN-168.
  • A band that is not in bands is KN-167.
  • A scene with solids on a page without kinetic.25d.js is KN-100, and so is a kinetic.25d.js from an earlier version than kinetic.wf.js, and a shape's number out of range, such as a negative radius.
  • A link to a layer that does not exist, such as a camera's from or a path point's on, is KN-164.

Lookup

The stage

KeyDefaultMeaning
srcthe clip's first <svg>A selector for the SVG element the solids draw into, looked for in the clip first.
grainnoneA selector for the <canvas> a solid's look.shade draws on.
viewan eye far off, the frame one unit acrossdistance, focal, roll, near, fade, center: the projection that solids() calls its camera.
lightsolids()'s lightdir, ramp, gamma, floor, gain, bounce, across.
rimnonecolor, width, base, edge, power, or false.
glowsnoneA list of { dir, color, gradient, size, strength, sharp, bleed }.
dropShadownoneblur (24), color (black), opacity (0.35), offset ([0, 0]): each solid's shadow on the solids behind it.

The stage is worked out once, when the layers are built. With layers(), the options target and canvas hand over the SVG group and the grain canvas in place of stage.src and stage.grain.

The shapes

shapeNumbersWhat it is
'plane'size (a number or [x, y])A flat rectangle.
'disc'radiusA flat circle.
'sector'radius, from, to, innerA flat slice, in degrees clockwise from straight up; with inner, part of a ring.
'capsule'radius (or [left, right]), lengthTwo circles length apart along x and the lines that touch both.
'box'size (a number or [x, y, z])A solid box.
'faces'faces: [{ pts, n }]Faces of your own, each three or more corners; as a value form, read at every frame, and an empty list draws nothing.
'polygon'sides, radiusA flat regular polygon, its first corner straight up.
'prism'sides, radius, depth, taperA polygon carried back depth into the frame, its back taper times the front's size.
'pyramid'sides, radius, heightA pyramid standing on its base.
'sphere'radius, and wedges with around or bands with alongA ball.

A solid layer

KeyMeaning
contentshape and the shape's numbers.
placeposition, rotate ([x, y, z] degrees, about x, then y, then z), scale (a number or [x, y, z]) and pivot, in the stage's units.
look.opacity0 to 1.
look.colorOne color, painted flat; a ramp of two or more #rrggbb colors read through the light; or a gradient, { gradient, angle } or { gradient, from, to }. A color can be a name, looked up in roles and swatches.
look.sideThe sides' own colors: an object by side name, or a list for a sphere's parts; each side a color as look.color takes it, or { color, shade }.
look.albedo, look.glowHow much light it gives back and how strongly the glows show on it, 1 when left out, read at time 0.
look.castsHow strong a shadow it casts with the stage's dropShadow, 0 to 1, 1 when left out.
look.acceptsfalse keeps shadows off it, read at time 0.
look.shadeA list of { look, marks } groups whose marks are { glow | edge, falloff, ink, amount, within }; a comp look's name; or { role, mirror: 'y' }.
look.clipAnother solid layer's id: draws this one only inside that one's outline; { layer, invert: true } draws it only outside.
hiddentrue keeps it from drawing, as an outline for look.clip.
bandOne of the scene's bands.
parentA null or another solid whose place this one's is inside; null to leave a comp's parent.

A kind: 'null' layer takes parent, place and controls. The top-level looks holds named grain looks, and bands lists the bands from the bottom up. A comp's looks holds named lists of groups and its marks named marks.

A camera layer and the world

KeyOnMeaning
perspectivecameraThe eye's distance in px from z = 0, 1000 when left out.
movescameramoves()'s list, with names for times, { distance, from } for a place in front of a layer, dolly: 'layerId', and to: { behavior: 'ride', path, distance, reach, wander, until, then }.
focuscameraThe depth of the plane in focus, read by { focus: { depth, max } }.
band: 'world'htmlPuts the layer in the world.
sizehtml in the world or in a group[width, height] in px, set on the element and laid out about its center.
place.positionhtml in the world or in a group[x, y, z] px from the world's middle.
grouphtml in the worldtrue: the layer holds the layers that name it as parent.
parenthtml, pathThe group the layer stands in.

When several cameras are listed, the scene uses the last one whose life includes the current time. A world layer's links can read 'self.cameraDistance' and 'self.screenScale'.

A path layer

KeyMeaning
content.pointsThe start, { on, at }, then each stop, { on, path, stop, also, head }, where also lists more paths on that layer drawn on with it.
content.betweenA selector for each straight stretch between stops.
content.head{ el, grow: [over, radius] }: the disc on the line's end between stops.
look.trim.endA { keys } track of distances in px or stop names ('start', 'A.start', 'A.end').
look.opacityThe ribbons' opacity.

Other layers read 'id.head', the distance reached in px, and 'id.A', the progress along stop A from 0 to 1.

Next

Camera, 3D and motion blur covers the calls under these layers, camera(), moves(), depth() and solids(), for a scene written in code.