Layer calls

A layer call is one of Kinetic's drawing calls, such as a halftone, a pencil drawing or a transition, written into a layer's look. Each of the call's options takes any value form, so an option can be a track that changes over time. This page covers look.effect, shade, backdrop, draw, boil and transition, the options key, and the three looks that make copies: smear, trails and repeat.

What a layer call is

Kinetic has calls that draw on an element. effect() prints a canvas as a halftone, a stipple or another effect, shade() paints shading from marks, blur() blurs what is under an element, draw() draws in pencil and pen, boil() makes a line wobble like a hand-drawn frame, and transition() gives the styles of a push, a wipe or another transition. In a scene written in code, you make the call in init() and change its options with set() in seek().

// In a scene written in code
init() {
    this.fx = effect(this.element.querySelector('canvas'), { scene: this, source: this.element.querySelector('img'), kind: 'halftone' });
},
seek(local) {
    this.fx.set({ cell: interpolate(local, [0, 2], [40, 12]) });
},

A layer call is the same call written as data. You give the call's options under the layer's look, and any option can be a value form, such as a track.

// The same call as a layer
{ id: 'print', kind: 'html', src: 'canvas', look: { effect: { kind: 'halftone', source: 'img', cell: { at: [0, 2], to: [40, 12] } } } }

The photo prints as a halftone whose dots shrink from 40 px to 12 px over two seconds.

  • Kinetic makes the call at the layer's first frame, on the layer's element, with the scene, so the call runs on the clip's time and goes away with it.
  • At every frame after that, Kinetic works out each option at the current time and calls set() when one has changed. An option that has not changed costs nothing.
  • effect, shade and draw draw on an HTML layer whose element is a <canvas>, and backdrop on any HTML layer's element. One element takes one of these four, and a layer with two of them is KN-162. Give each its own layer and its own element.
  • boil goes on an SVG layer, and transition, smear, trails and repeat on a layer's elements.

The value forms are on Values, and the layer's other keys on Moving an element.

look.effect

look.effect runs effect() on a canvas. It takes kind, source, and the kind's own parameters.

{
    id: 'print', kind: 'html', src: '.print',
    look: { effect: { kind: 'halftone', source: '.photo', cell: { at: [0, 3], to: [40, 8] }, angle: 45, ink: '#1b1530', paper: '#f3ead8' } },
}

The photo in .photo prints on the canvas as dark dots on cream paper, large at first and fine by 3 seconds.

  • kind is 'halftone', 'stipple', 'splatter', 'dither', 'duotone' or 'boil', and an effect with no kind (and no options) is KN-162.
  • source is a selector for the <img>, <video> or <canvas> it reads, looked for in the clip. A selector that finds nothing is KN-168. Hide an <img> source with CSS when only the print should show.
  • Each kind's parameters (cell, scale, density, ink, ...) are listed on Effects.

A kind that changes makes the effect again, on a fresh copy of the canvas, since a canvas takes one effect.

look: { effect: { kind: { keys: [[0, ['hold', 'halftone']], [2, ['hold', 'dither']]] }, source: '.photo' } }

The photo is a halftone for 2 seconds and then turns into a dither.

look.shade

look.shade runs shade() on a canvas. It takes kind, marks, move, and the rest of shade()'s options, such as scale, fps, delay and freeze.

{
    id: 'shading', kind: 'html', src: '.shading',
    look: {
        shade: {
            kind: 'stipple', scale: 2, fps: 4,
            marks: [
                { glow: { at: [{ at: [0, 4], to: [100, 260] }, 120], radius: 200, invert: true }, ink: '#2c5a46', clip: { circle: [180, 180, 150] } },
            ],
        },
    },
}

A green stippled sphere is lit from the upper left, and the light slides to the right over 4 seconds while the specks scatter four times a second.

The marks are a list of data, one object per mark, as shade()'s m.marks([...]) takes them, in px from the canvas's top left. Each number in them is a value, worked out at the time the marks are painted.

  • { glow: { at, radius, invert }, ink, clip } paints a glow from a point.
  • { band: { from, to, width, side }, ink } paints a stripe along a line.
  • { edge: { width }, clip } paints inward from the clip's outline.
  • { path: { d, width, side }, ink } paints along a path.
  • { fill: 0.3, clip } paints the same amount everywhere in the clip.

Every mark also takes amount, ink and falloff, as listed on Shading.

move gives the name of a function in the scene's fns, the function that shade() takes as move(t).

wildflower.kinetic.layers.scene('rings', {
    layers: [
        {
            id: 'ring', kind: 'html', src: 'canvas',
            look: { shade: { kind: 'stipple', fps: 2, move: 'grow', marks: [{ edge: { width: 20 }, clip: { circle: [140, 140, 60] } }] } },
        },
    ],
}, { fns: { grow: (t) => ({ scale: 1 + (t % 1), origin: [140, 140] }) } });

A stippled ring grows from its center, and the specks grow with it, starting again every second. A name that is not in fns is KN-166, and move: null turns the move off.

look.backdrop

look.backdrop runs blur() on any element, which blurs what is under the element where its marks paint. It takes radius (px), marks, fps, delay and freeze.

{
    id: 'pane', kind: 'html', src: '.pane',
    look: { backdrop: { radius: { at: [0, 2], to: [0, 14] }, marks: [{ glow: { at: [{ at: [0, 4], to: [0, 520] }, 120], radius: 220 } }] } },
}

A soft spot of frosted glass slides across the heading behind the pane, and it grows blurrier over the first 2 seconds. The marks are the same data as look.shade's, in px from the element's top left.

look.draw

look.draw runs draw() on a canvas. It takes inks, start, end, strokes, and the hand's options: wobble, pressure, speed, tooth, lead, seed, paper and drawn.

{
    id: 'sketch', kind: 'html', src: '.sheet',
    look: {
        draw: {
            start: 0.2, end: 3.5,
            inks: { lead: { tool: 'pencil' }, pen: { tool: 'pen' } },
            strokes: [
                { construct: { points: [[180, 30], [180, 340]] }, ink: 'lead' },
                { contour: { d: 'M180 60 C 150 60 144 110 150 150 C 116 180 90 230 106 290 C 122 340 238 340 254 290 C 270 230 244 180 210 150 C 216 110 210 60 180 60 Z' }, ink: 'pen' },
                { pause: 0.3 },
                { hatch: { clip: { circle: [210, 260, 50] }, angle: -50, spacing: 7 }, ink: 'lead' },
            ],
        },
    },
}

A pencil line goes down the middle, a pen draws a pear's outline around it, and after a short pause the pencil hatches the pear's lower right, all between 0.2 and 3.5 seconds.

  • Each stroke is an object with one of construct, contour, hatch, accent, text or pause, holding that call's options, and the stroke's own keys beside it, such as ink, pressure, at and group. A stroke with none of them is KN-162.
  • { pause: s } waits s seconds before the next stroke.
  • start and end are times in the clip, in the scene's unit.
  • The strokes, start and end are read once, when the drawing is made. After that, a track can change inks and the hand's options.

look.boil

look.boil runs boil() on an SVG layer's content.d. The outline wobbles a little and changes a few times a second, the way the lines in a hand-drawn animation do. It takes amount (px), scale (px), fps, delay, seed and detail.

{
    id: 'sun', kind: 'svg', src: '.sun',
    content: { d: 'M 980 90 A 110 110 0 1 1 979.99 90 Z' },
    look: { boil: { amount: { at: [0.5, 2.5], to: [0, 5] }, scale: 40, fps: 8 } },
}

The sun is a clean circle at first and starts to wobble at half a second, more and more until 2.5 seconds, with a new wobble eight times a second.

  • The layer boils the d that its content.d gives, so give the outline there as well as in the markup.
  • look.boil on a layer that is not an SVG layer is KN-162. To boil a canvas, an image or a video, use look.effect with kind: 'boil'.
  • Other layers read the boiled outline as 'sun.d' (Values).
<div id="stage" data-composition-id="main" data-start="0" data-duration="5" data-width="1280" data-height="720" data-fps="30">
    <div class="layer" data-component="sketch" data-start="0" data-duration="5">
        <svg viewBox="0 0 1280 720">
            <path class="sun" d="M 980 90 A 110 110 0 1 1 979.99 90 Z" />
            <path class="bird" d="M 420 220 Q 450 190 480 220 Q 510 190 540 220" />
            <path class="hill" d="M 0 560 C 260 420 520 420 760 520 C 940 600 1100 560 1280 470" />
        </svg>
    </div>
</div>
wildflower.kinetic.layers.scene('sketch', {
    layers: [
        {
            id: 'sun', kind: 'svg', src: '.sun',
            content: { d: 'M 980 90 A 110 110 0 1 1 979.99 90 Z' },
            look: { boil: { amount: { at: [0.5, 2.5], to: [0, 5] }, scale: 40, fps: 8 } },
        },
        {
            id: 'bird', kind: 'svg', src: '.bird',
            content: { d: 'M 420 220 Q 450 190 480 220 Q 510 190 540 220' },
            place: { translate: [{ at: [0, 5], to: [0, 240] }, 0] },
            look: { boil: { amount: 2, scale: 20, fps: 8, seed: 9 } },
        },
        {
            id: 'hill', kind: 'svg', src: '.hill',
            content: { d: 'M 0 560 C 260 420 520 420 760 520 C 940 600 1100 560 1280 470' },
            look: { boil: { amount: 3, scale: 60, fps: 8, seed: 4 } },
        },
    ],
});
html, body { margin: 0; background: #0a0b10; }

#stage { position: relative; overflow: hidden; background: #f3efe6; }

.layer { position: absolute; inset: 0; }

svg { position: absolute; inset: 0; width: 100%; height: 100%; }

path { fill: none; stroke: #2a2620; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }

.sun { stroke: #d0632b; }

[data-composition-id]:not([data-kinetic-ready]) { visibility: hidden; }
Line boil

look.transition

look.transition writes transition()'s styles on an element, for an element inside a clip that should come in or go out the way a clip does. It takes kind, p (the progress, from 0 to 1), direction, and side, 'in' (the default) or 'out'.

{ id: 'enter', kind: 'html', src: '.frame', look: { transition: { kind: 'iris', p: { at: [0.3, 1.2], to: [0, 1], ease: 'power2.inOut' } } } }

The frame opens as a growing circle from its center between 0.3 and 1.2 seconds.

  • p is the eased progress, so give a track its own ease.
  • The kinds are those on Transitions except luma, halftone and dissolve, which mask a whole clip and are KN-100 here.
  • On the 'in' side, p = 0 is the start of the way in, and at p = 1 the element is as the CSS has it. On the 'out' side, the element is as the CSS has it at p = 0, and p = 1 is the end of the way out.
  • At every frame the layer writes the transition's opacity, translate, scale, rotate, clipPath, filter and zIndex, and clears the ones the kind leaves out. A look.opacity on the same layer replaces the transition's opacity.

One layer gives one side. For an element that comes in and goes out, put the way in on a wrapper and the way out on the element inside it.

<div id="stage" data-composition-id="main" data-start="0" data-duration="5" data-width="1280" data-height="720" data-fps="30">
    <div class="layer" data-component="card" data-start="0" data-duration="5">
        <div class="frame">
            <div class="card">
                <h1>Launch</h1>
                <p>Thursday, 9 a.m.</p>
            </div>
        </div>
    </div>
</div>
wildflower.kinetic.layers.scene('card', {
    layers: [
        {
            id: 'enter', kind: 'html', src: '.frame',
            look: { transition: { kind: 'iris', p: { at: [0.3, 1.2], to: [0, 1], ease: 'power2.inOut' } } },
        },
        {
            id: 'leave', kind: 'html', src: '.card',
            look: { transition: { kind: 'push', direction: 'from-left', side: 'out', p: { at: [3.6, 4.4], to: [0, 1], ease: 'power3.in' } } },
        },
    ],
});
html, body { margin: 0; background: #0a0b10; }

#stage { position: relative; overflow: hidden; background: #0b0f1a; }

.layer { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }

.frame { width: 760px; height: 400px; border-radius: 24px; overflow: hidden; }

.card { width: 100%; height: 100%; background: #9d7bff; color: #0b0f1a; display: flex; flex-direction: column; align-items: center; justify-content: center; }

h1 { margin: 0; font: 800 120px system-ui, sans-serif; }

p { margin: 12px 0 0; font: 500 34px system-ui, sans-serif; }

[data-composition-id]:not([data-kinetic-ready]) { visibility: hidden; }
A transition in and out

The card opens as a circle, holds, and then slides out to the right inside its frame.

options

options on effect, shade, backdrop or draw gives several options as one value. The value is an object of options, and its options replace any of the same name beside it.

wildflower.kinetic.layers.scene('print', {
    layers: [
        { id: 'print', kind: 'html', src: '.print', look: { effect: { kind: 'stipple', source: '.photo', options: { call: 'grade', args: [{ rate: 1 }] } } } },
    ],
}, { fns: { grade: (t) => ({ scale: t < 2 ? 2 : 4, density: Math.min(0.3, t / 10) }) } });

The photo prints as a stipple that darkens over 3 seconds, and its specks double in size at 2 seconds. A value that is not an object is KN-165.

look.smear

look.smear draws the layer's own motion as see-through copies of its element beside it, as a camera's shutter blurs a fast move. It takes samples (the number of copies, 8), angle (the shutter angle in degrees, 180) and fps (the composition's by default), as smear() takes them.

{
    id: 'puck', kind: 'html', src: '.puck',
    place: { translate: [{ at: [0.5, 1.5], to: [0, 460], ease: 'power2.inOut' }, 0] },
    look: { smear: { samples: 12, angle: 360 } },
}

The puck stretches into a short streak while it moves fast and is a sharp circle again when it stops.

  • Each copy is a clone of the element placed after it, at the layer's style a little later in the shutter, with 1 / samples of its opacity and mix-blend-mode: plus-lighter. Give the parent isolation: isolate so the copies add up to the element where they overlap.
  • The copies take the layer's place, look.opacity and look.style.
  • In a render with a shutter, the layer draws one copy, since the render blurs it already.

look.trails

look.trails draws the marks a moving thing leaves behind, as trails() makes them. Its kind is 'ghosts', 'ribbon' or 'dots', and any other kind is KN-162.

Ghosts

{ kind: 'ghosts', of, count, lag, fade, scale } draws fading copies of another layer where it was a moment before. of is that layer's id. The copies are clones of the <template> in the trails layer's element, and each one takes the style of the of layer lag seconds further back than the last.

  • count is how many copies, from 1 to 64 (6).
  • lag is the time between copies (0.04 seconds).
  • fade is how much opacity the last copy loses, from 0 to 1 (0.8).
  • scale, from 0 to 1 (0), shrinks the copies, so copy k is drawn at 1 - k × scale of its size.

An of that matches no layer is KN-164.

<div id="stage" data-composition-id="main" data-start="0" data-duration="4" data-width="1280" data-height="720" data-fps="30">
    <div class="layer" data-component="bounce" data-start="0" data-duration="4">
        <div class="floor"></div>
        <div class="ghosts">
            <template><div class="dot"></div></template>
        </div>
        <div class="dot ball"></div>
    </div>
</div>
wildflower.kinetic.layers.scene('bounce', {
    layers: [
        {
            id: 'ball', kind: 'html', src: '.ball',
            place: {
                translate: [
                    { at: [0, 3.5], to: [0, 1000], ease: 'power1.inOut' },
                    { keys: [[0, 0], [0.6, -380], [1.2, 0], [1.75, -260], [2.3, 0], [2.8, -140], [3.3, 0]], ease: 'sine.inOut' },
                ],
            },
        },
        { id: 'trail', kind: 'html', src: '.ghosts', look: { trails: { kind: 'ghosts', of: 'ball', count: 10, lag: 0.035, fade: 0.9, scale: 0.05 } } },
    ],
});
html, body { margin: 0; background: #0a0b10; }

#stage { position: relative; overflow: hidden; background: #0b0f1a; }

.layer, .ghosts { position: absolute; inset: 0; }

.floor { position: absolute; left: 80px; right: 80px; top: 592px; height: 4px; border-radius: 2px; background: #2a2f45; }

.dot { position: absolute; left: 140px; top: 560px; width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 50%; background: #9d7bff; }

.ball { background: #f2d16b; }

[data-composition-id]:not([data-kinetic-ready]) { visibility: hidden; }
Ghosts behind a moving dot

The yellow ball hops three times across the floor, each hop lower, with ten purple copies behind it that fade and shrink. The ghosts' <template> holds a dot with the ball's own place in the CSS, so each copy sits where the ball was.

Ribbon

{ kind: 'ribbon', d, u, length, by }, on an SVG <path>, draws the stretch of the path d just behind a point that moves along it. u is the point's place along the path, from 0 to 1, and length is how much of the path the ribbon covers (0.1).

{
    id: 'ribbon', kind: 'svg', src: '.ribbon',
    look: { trails: { kind: 'ribbon', d: 'M 40 300 C 200 40 440 40 600 300', u: { at: [0, 3.5], to: [0, 1] }, length: 0.2 } },
}

A short purple stroke runs along the arch from left to right in 3.5 seconds, a fifth of the arch long. The layer writes the ribbon into the path's d, and other layers read it as 'ribbon.d'.

Dots

{ kind: 'dots', d, u, count, by, past, future } places count copies of the element's <template> evenly along the path d (12). A dot is past once u reaches it, and future until then. past and future are the CSS styles for each state.

{
    id: 'stops', kind: 'html', src: '.stops',
    look: {
        trails: {
            kind: 'dots', d: 'M 40 300 C 200 40 440 40 600 300', u: { at: [0, 3.5], to: [0, 1] }, count: 9,
            past: { background: '#9d7bff' }, future: { background: '#444b66' },
        },
    },
}

Nine gray stops sit along the arch, and each one turns purple as the ribbon passes it. Each dot gets left and top in px, so give the template's element position: absolute and a negative margin of half its size. by: 'segment' spaces the dots, or measures the ribbon, by the path's segments instead of its length.

look.repeat

look.repeat makes copies of the element's <template>, each one a step on from the one before, as repeat() makes them. It takes count, translate ([x, y] px), rotate (degrees), scale, opacity, offset, origin and each: { scale }.

{ id: 'fan', kind: 'html', src: '.fan', look: { repeat: { count: { at: [0, 3], to: [1, 12] }, rotate: 30, opacity: [1, 0.3] } } },
{ id: 'count', kind: 'html', src: '.count', content: { text: { from: 'fan.count' } } },

Blades fan out one by one around a point, each turned 30 degrees on from the last and fainter, until twelve make a full circle at 3 seconds, and the counter shows how many there are.

  • count is rounded to a whole number, and 0 or less makes no copies.
  • Each step is applied again for each copy, so a turn with a move makes an arc, and a scale with a move a spiral.
  • opacity is [first, last], or the last copy's alone.
  • offset shifts the series by that many steps, so a negative offset puts copies on both sides of the first.
  • origin is the copies' transform-origin, and each: { scale } scales every copy about its own origin after its step.
  • The layer reports 'id.count' and its last copy's 'id.transform' and 'id.transformOrigin'. List a layer that reads them after this one.

This is a look of its own, apart from a layer's repeat key, which makes copies on a count or over time with their own tracks.

Lookup

LookThe callLayerOptionsWhat a track can change
effecteffect(canvas)html, a canvaskind, source (a selector), the kind's parameters, options.Every parameter. A new kind makes it again.
shadeshade(canvas)html, a canvaskind, marks ({ glow: { at, radius, invert }, ink, clip }, { band }, { edge }, { path }, { fill, clip }), move (a function's name in fns), the rest of shade()'s options, options.Every option and mark. A new kind makes it again.
backdropblur(element)html, any elementradius, marks, fps, delay, freeze, options.All of them.
drawdraw(canvas)html, a canvasinks, start, end, strokes ({ contour: { d }, ink }, { hatch: { clip, angle, spacing } }, { pause: s }, ...), the hand's options, options.inks and the hand's options.
boilboil(d) on the layer's content.dsvgamount, scale, fps, delay, seed, detail.All of them.
transitiontransition(kind, p)anykind, p, direction, side ('in' or 'out').All of them.
LookOptionsWhat it draws
smear{ samples, angle, fps }The layer's own motion, as copies of its element beside it.
trails{ kind: 'ghosts', of, count, lag, fade, scale }Fading copies of another layer where it was a moment before.
{ kind: 'ribbon', d, u, length, by }, on an SVG pathThe stretch of a path behind a point moving along it.
{ kind: 'dots', d, u, count, by, past, future }Marks along a path, each past or future.
repeat{ count, translate, rotate, scale, opacity, offset, origin, each: { scale } }repeat()'s copies of the element's template, each one a step on from the one before.

Next: Solids, cameras and paths.