Verbs

Entrance, exit and emphasis animations (k.draw, k.fade_out, k.indicate, k.morph).

Contents:

  • k.draw: Entrance verb: traces the outline and then fills it.
  • k.write: Entrance verb: writes the text character by character.
  • k.fade_in: Entrance verb: opacity from 0 to 1.
  • k.fade_out: Exit verb: opacity from 1 to 0, and then the objects leave the scene.
  • k.grow: Entrance verb: scales up from the center (default) or from a side (from_="bottom", "left", "top-left"...).
  • k.shrink: Exit verb: the inverse of k.grow.
  • k.indicate: Emphasis: temporarily tints and pulses the object; the final state equals the initial one.
  • k.flash: Emphasis: a ring of light that expands from the object's edge and fades away.
  • k.squash: Emphasis: an elastic squash against the object's base; amount= controls the intensity.
  • k.follow: Motion: the object travels along a path (the outline of another object or a list of points, in world coordinates).
  • k.sound: Audio: plays a sound file at the moment it is scheduled (zero duration in the script).
  • k.sfx: Built-in sound effects for k.sound: k.sfx.click(), tick(), pop(), swish(), whoosh() and ding() return the file of each effect.
  • k.music: Background music from the scheduled instant to the end of the scene: gain= sets its level, duck= its level while a voice speaks (0.25 = a quarter; 1 = no ducking), and fade= fades it in at its start and out at the end of the scene, in seconds.
  • k.morph: Swap: a leaves, b enters and the matching parts travel between them (identical characters and tokens slide; the rest fades out and in).

Back to the reference index.

k.draw (function)

k.draw(
    *objs: Node,
    duration: float | None = None,
    ease: EaseLike | None = None,
    delay: float = 0.0,
) -> Animation

Entrance verb: traces the outline and then fills it. The object enters the scene at the start of the animation. If the object is a component with enter(), the verb uses that implementation.

Parameters:

Name Type Default Description
*objs Node variadic
duration float | None None
ease EaseLike | None None
delay float 0.0

Example:

@k.scene
def drawing(s: k.Scene):
    circle = k.Circle(r=1.5, fill=k.BLUE, fill_opacity=0.4).place(at="center")
    s.play(k.draw(circle))
    s.wait(0.5)

See also: k.write, k.fade_in, k.grow.

k.write (function)

k.write(
    *objs: Node,
    duration: float | None = None,
    ease: EaseLike | None = None,
    delay: float = 0.0,
) -> Animation

Entrance verb: writes the text character by character. Other objects passed to k.write are drawn as with k.draw.

Parameters:

Name Type Default Description
*objs Node variadic
duration float | None None
ease EaseLike | None None
delay float 0.0

Example:

@k.scene
def writing(s: k.Scene):
    title = k.Text("Hello, kinemo", size=0.8).place(at="center")
    s.play(k.write(title), duration=1.5)
    s.wait(0.5)

See also: k.Text, k.draw, k.fade_in.

k.fade_in (function)

k.fade_in(
    *objs: Node,
    shift: VecLike | None = None,
    duration: float | None = None,
    ease: EaseLike | None = None,
    delay: float = 0.0,
) -> Animation

Entrance verb: opacity from 0 to 1. Accepts multiple objects; shift=(dx, dy) makes each object arrive from an offset of -shift to its final position.

Parameters:

Name Type Default Description
*objs Node variadic
shift VecLike | None None Accepts multiple objects; shift=(dx, dy) makes each object arrive from an offset of -shift to its final position.
duration float | None None
ease EaseLike | None None
delay float 0.0

Example:

@k.scene
def appear(s: k.Scene):
    a = k.Square(1.2).place(at="center")
    label = k.Text("square").place(below=a, gap=0.3)
    s.play(k.fade_in(a, label, shift=(0, 0.5)))
    s.wait(0.5)

See also: k.fade_out, k.draw.

k.fade_out (function)

k.fade_out(
    *objs: Node,
    shift: VecLike | None = None,
    duration: float | None = None,
    ease: EaseLike | None = None,
    delay: float = 0.0,
) -> Animation

Exit verb: opacity from 1 to 0, and then the objects leave the scene. Accepts multiple objects and shift= to exit with an offset.

Parameters:

Name Type Default Description
*objs Node variadic
shift VecLike | None None Accepts multiple objects and shift= to exit with an offset.
duration float | None None
ease EaseLike | None None
delay float 0.0

Example:

@k.scene
def vanish(s: k.Scene):
    title = k.Text("See you soon").place(at="center")
    s.play(k.write(title))
    s.play(k.fade_out(title, shift=(0, 0.5)))

See also: k.fade_in, k.shrink, s.remove.

k.grow (function)

k.grow(
    obj: Node,
    from_: Anchor = "center",
    *,
    duration: float | None = None,
    ease: EaseLike | None = None,
    delay: float = 0.0,
) -> Animation

Entrance verb: scales up from the center (default) or from a side (from_="bottom", "left", "top-left"...). It is the natural entrance for bars and boxes.

Parameters:

Name Type Default Description
obj Node required
from_ Anchor "center" Entrance verb: scales up from the center (default) or from a side (from_="bottom", "left", "top-left"...).
duration float | None None
ease EaseLike | None None
delay float 0.0

Example:

@k.scene
def grow(s: k.Scene):
    bar = k.Bar(6, label=True).place(at="center")
    s.play(k.grow(bar, from_="bottom"))
    s.wait(0.5)

See also: k.shrink, k.Bar, k.stagger.

k.shrink (function)

k.shrink(
    obj: Node,
    to: Anchor = "center",
    *,
    duration: float | None = None,
    ease: EaseLike | None = None,
    delay: float = 0.0,
) -> Animation

Exit verb: the inverse of k.grow. Shrinks toward the center (default) or toward a side (to="bottom") and takes the object out of the scene.

Parameters:

Name Type Default Description
obj Node required
to Anchor "center" Shrinks toward the center (default) or toward a side (to="bottom") and takes the object out of the scene.
duration float | None None
ease EaseLike | None None
delay float 0.0

Example:

@k.scene
def shrink(s: k.Scene):
    box = k.RoundedRect(w=3, h=2).place(at="center")
    s.play(k.draw(box))
    s.play(k.shrink(box, to="bottom"))

See also: k.grow, k.fade_out.

k.indicate (function)

k.indicate(
    obj: Node,
    color: ColorLike = k.YELLOW,
    scale: float = 1.2,
    *,
    duration: float | None = None,
    ease: EaseLike | None = None,
    delay: float = 0.0,
) -> Animation

Emphasis: temporarily tints and pulses the object; the final state equals the initial one. It is reversible, so it also works inside s.during.

Parameters:

Name Type Default Description
obj Node required
color ColorLike k.YELLOW
scale float 1.2
duration float | None None
ease EaseLike | None None
delay float 0.0

Example:

@k.scene
def emphasis(s: k.Scene):
    word = k.Text("important", size=0.8).place(at="center")
    s.play(k.write(word))
    s.play(k.indicate(word, color=k.YELLOW, scale=1.3))
    s.wait(0.5)

See also: k.flash, k.squash, s.during.

k.flash (function)

k.flash(
    obj: Node,
    color: ColorLike = k.YELLOW,
    *,
    duration: float | None = None,
    ease: EaseLike | None = None,
    delay: float = 0.0,
) -> Animation

Emphasis: a ring of light that expands from the object's edge and fades away. It does not change the object.

Parameters:

Name Type Default Description
obj Node required
color ColorLike k.YELLOW
duration float | None None
ease EaseLike | None None
delay float 0.0

Example:

@k.scene
def pulse(s: k.Scene):
    dot = k.Dot(r=0.3).place(at="center")
    s.add(dot)
    s.play(k.flash(dot, color=k.YELLOW))
    s.wait(0.5)

See also: k.indicate, k.when.

k.squash (function)

k.squash(
    obj: Node,
    amount: float = 0.3,
    *,
    duration: float | None = None,
    ease: EaseLike | None = None,
    delay: float = 0.0,
) -> Animation

Emphasis: an elastic squash against the object's base; amount= controls the intensity. The state returns to the initial one. Good for impacts.

Parameters:

Name Type Default Description
obj Node required
amount float 0.3 Emphasis: an elastic squash against the object's base; amount= controls the intensity.
duration float | None None
ease EaseLike | None None
delay float 0.0

Example:

@k.scene
def impact(s: k.Scene):
    ball = k.Circle(r=0.6, fill=k.ORANGE, fill_opacity=1).place(at="center")
    s.add(ball)
    s.play(k.squash(ball, amount=0.4))
    s.wait(0.5)

See also: k.indicate, k.simulate.

k.follow (function)

k.follow(
    obj: Node,
    path: FollowPath,
    *,
    rotate: bool = False,
    duration: float | None = None,
    ease: EaseLike | None = None,
    delay: float = 0.0,
) -> Animation

Motion: the object travels along a path (the outline of another object or a list of points, in world coordinates). rotate=True aligns the object with the tangent.

Parameters:

Name Type Default Description
obj Node required
path FollowPath required
rotate bool False rotate=True aligns the object with the tangent.
duration float | None None
ease EaseLike | None None
delay float 0.0

Example:

@k.scene
def orbit(s: k.Scene):
    track = k.Circle(r=2.5, stroke=k.GRAY).place(at="center")
    planet = k.Dot(r=0.2, fill=k.BLUE)
    s.add(track, planet)
    s.play(k.follow(planet, track), duration=3, ease=k.ease.linear)

See also: k.trace, k.Path.

k.sound (function)

k.sound(path: str, gain: float = 1.0) -> Animation

Audio: plays a sound file at the moment it is scheduled (zero duration in the script). gain= adjusts the volume. For narration, use s.voice.

Parameters:

Name Type Default Description
path str required
gain float 1.0 gain= adjusts the volume.

Example:

@k.scene
def click(s: k.Scene):
    button = k.RoundedRect(w=2, h=0.8).place(at="center")
    s.play(k.draw(button))
    s.play(k.sound("click.wav", gain=0.8), k.indicate(button))

See also: s.voice, k.sfx.

k.sfx (value)

k.sfx: SoundEffects

Built-in sound effects for k.sound: k.sfx.click(), tick(), pop(), swish(), whoosh() and ding() return the file of each effect. They are made by kinemo (no third-party license) the first time they are used, in the project's cache, and sound the same in every render. Overlapping sounds never clip: the mix ends in a limiter.

Example:

@k.scene
def cells(s: k.Scene):
    row = k.Row(*[k.Square(0.6) for _ in range(4)], gap=0.2).place(at="center")
    s.play(k.draw(row))
    for cell in row:
        s.play(cell.to(fill=k.YELLOW, fill_opacity=1), k.sound(k.sfx.click(), gain=0.5), duration=0.3)
    s.play(k.sound(k.sfx.ding(), gain=0.6), k.indicate(row))

See also: k.sound, k.music.

k.music (function)

k.music(
    path: str,
    gain: float = 0.3,
    duck: float = 0.25,
    fade: float = 1.0,
) -> Animation

Background music from the scheduled instant to the end of the scene: gain= sets its level, duck= its level while a voice speaks (0.25 = a quarter; 1 = no ducking), and fade= fades it in at its start and out at the end of the scene, in seconds.

Parameters:

Name Type Default Description
path str required
gain float 0.3 Background music from the scheduled instant to the end of the scene: gain= sets its level, duck= its level while a voice speaks (0.25 = a quarter; 1 = no ducking), and fade= fades it in at its start and out at the end of the scene, in seconds.
duck float 0.25 Background music from the scheduled instant to the end of the scene: gain= sets its level, duck= its level while a voice speaks (0.25 = a quarter; 1 = no ducking), and fade= fades it in at its start and out at the end of the scene, in seconds.
fade float 1.0 Background music from the scheduled instant to the end of the scene: gain= sets its level, duck= its level while a voice speaks (0.25 = a quarter; 1 = no ducking), and fade= fades it in at its start and out at the end of the scene, in seconds.

Example:

@k.scene
def theme(s: k.Scene):
    s.play(k.music("click.wav", gain=0.3, duck=0.25, fade=0.5))
    title = k.Text("Episode 1").place(at="center")
    with s.voice("Welcome to the first episode."):  # kinemo: allow W1401
        s.play(k.write(title))

See also: k.sound, s.voice.

k.morph (function)

k.morph(
    a: Node,
    b: Node,
    *,
    match: MorphMatch | None = None,
    duration: float | None = None,
    ease: EaseLike | None = None,
    delay: float = 0.0,
) -> Animation

Swap: a leaves, b enters and the matching parts travel between them (identical characters and tokens slide; the rest fades out and in). match={part_a: part_b} forces matches. With nothing in common, it does a warp + crossfade and emits W0801.

Parameters:

Name Type Default Description
a Node required Swap: a leaves, b enters and the matching parts travel between them (identical characters and tokens slide; the rest fades out and in).
b Node required Swap: a leaves, b enters and the matching parts travel between them (identical characters and tokens slide; the rest fades out and in).
match MorphMatch | None None match={part_a: part_b} forces matches.
duration float | None None
ease EaseLike | None None
delay float 0.0

Example:

@k.scene
def swap(s: k.Scene):
    a = k.Text("a + b = c", size=0.8).place(at="center")
    b = k.Text("c = a + b", size=0.8).place(at="center")
    s.play(k.write(a))
    s.play(k.morph(a, b))
    s.wait(0.5)

See also: k.Code, k.write, k.fade_out.