Animation

Ebi lays out animations in time the way a Box lays out elements in space. An Animation schedules its children. Its gap, padding, and margin take durations such as 250ms, while the shapes still use points or percentages for their positions.

Loading Ebi…
fn caption(x: Percent, title: String): Element {
    return <Text font_size={12pt} font_weight={650} fill="light1" position={[x, 37%]}
        x_align={Align.Center} y_align={Align.Center}>{title}</Text>
}

let rise = [0%, -44%]
let fall = [0%, 44%]

fn bob(item: Element, leg: Duration): Animation {
    return <Animation flow="sequence">
        {item.shift(rise, duration=leg, ease="smootherstep")}
        {item.shift(fall, duration=leg, ease="smootherstep")}
    </Animation>
}

fn square(x: Percent, color: Color): Element {
    return <Box w-32 h-32 rounded-6 fill={color} position={[x, 16%]}
        x_align={Align.Center} y_align={Align.Center} />
}

let blue = square(-33%, Color("blue3"))
let violet = square(-11%, Color("purple3"))
let orange = square(11%, Color("orange2"))
let green = square(33%, Color("green3"))

<Animation>
    {caption(-33%, "Parallel")}
    {caption(-11%, "Sequence")}
    {caption(11%, "Offset")}
    {caption(33%, "Repeat")}
    {blue}{violet}{orange}{green}
</Animation>

<Animation duration={3s}>
    <Animation flow="parallel">
        {bob(blue, 950ms)}
        {blue.rotate_to(180deg, duration=1.9s, ease="linear")}
    </Animation>
    <Animation flow="sequence" padding={150ms} gap={180ms}>
        {violet.shift(rise, duration=650ms, ease="smootherstep")}
        <Animation margin_start={150ms}>
            {violet.rotate_to(180deg, duration=650ms, ease="linear")}
        </Animation>
        {violet.shift(fall, duration=650ms, ease="smootherstep")}
    </Animation>
    <Animation position_mode="absolute" offset={750ms}>
        {bob(orange, 650ms)}
    </Animation>
    {bob(green, 350ms).repeat(4)}
</Animation>

The blue and purple squares have separate movement and rotation actions. The blue square bobs and rotates at the same time. The purple square rises, pauses for the gap plus the turn’s leading margin, turns in place, then comes back down. The orange square starts at 750ms, and the green square runs four short cycles. Try changing the purple square’s gap to 0ms or the orange square’s offset to 1s.

Flow and spacing

ControlEffect on the timeline
flow="parallel"Children run together by default. Each has its own duration. An auto-sized group takes the longest in-flow span plus its own padding.
flow="sequence"Children play in order. Top-level animation statements also play in order.
gapInserts time between adjacent children in a sequence.
padding, padding_start, padding_endReserve time at the start and end of a group. padding sets both sides, and the side-specific attributes can override it.
margin, margin_start, margin_endReserve time around a child in its parent’s flow. margin sets both sides.
wait(500ms)Adds an explicit pause as a child or top-level statement.

Nest the two flows to build independent sequences inside one parallel group. In the demo, the blue square’s upward and downward moves form one sequence while its rotation runs alongside it.

Align work in a fixed duration

Set a group’s duration to give it a time window. Use justify to distribute spare time inside that window, after padding, gaps, and margins. Each square below has the same rise, return, and three-second window.

type Alignment = "start" | "center" | "end" | "between" | "around" | "evenly"

fn compare(x: Percent, mode: Alignment): Animation {
    let tile = <Box w-22 h-22 rounded-5 bg-blue3 position={[x, 20%]}
        x_align={Align.Center} y_align={Align.Center} />
    return <Animation>
        <Text font_size={10pt} fill="light1" position={[x, 39%]}
            x_align={Align.Center} y_align={Align.Center}>{mode}</Text>
        {tile}
        <Animation flow="sequence" duration={3s} justify={mode}>
            {tile.shift([0%, -50%], duration=550ms, ease="smootherstep")}
            {tile.shift([0%, 50%], duration=550ms, ease="smootherstep")}
        </Animation>
    </Animation>
}

<Animation>
    {compare(-40%, "start")}
    {compare(-24%, "center")}
    {compare(-8%, "end")}
    {compare(8%, "between")}
    {compare(24%, "around")}
    {compare(40%, "evenly")}
</Animation>
  • start, center, and end place the sequence as a block. In parallel flow, center and end align each child against the window individually.
  • between puts all spare time between the moves, so that square spends the longest at the top.
  • around gives the outside edges half as much spare time as the space between the moves. evenly gives each space the same share.

Size, offset, and clip a group

ControlEffect on the timeline
duration="auto"The default. Measures the group's in-flow children.
duration="match_parent"Uses the constrained parent’s content duration after padding and the child’s margins. Give the parent a fixed duration or a duration resolved from its own parent.
offsetShifts a child earlier or later from its scheduled start. A relative child keeps its original slot in the sequence.
position_mode="absolute"Places a child from the parent’s content start, plus its offset and leading margin. It takes up zero time in the parent’s flow.
overflow="hidden"The default. Clips child actions to the group’s window. A clipped move holds the value it reached at the boundary.
overflow="visible"Lets children keep running beyond the group’s window, within any enclosing time limits.

The blue square takes the full padded window to go up and down. The purple square’s rise starts 250ms early in its sequence, and its return keeps its original start. The orange square freezes halfway down when its group ends. The green square completes the same move because its group allows overflow.

fn marker(x: Percent, color: Color): Element {
    return <Box w-30 h-30 rounded-6 fill={color} position={[x, 18%]}
        x_align={Align.Center} y_align={Align.Center} />
}

fn caption(x: Percent, title: String): Element {
    return <Text font_size={12pt} fill="light1" position={[x, 39%]}
        x_align={Align.Center} y_align={Align.Center}>{title}</Text>
}

let blue = marker(-33%, Color("blue3"))
let purple = marker(-11%, Color("purple3"))
let orange = marker(11%, Color("orange2"))
let green = marker(33%, Color("green3"))
let rise = [0%, -46%]
let fall = [0%, 46%]

fn round_trip(item: Element, clipping: "hidden" | "visible"): Animation {
    return <Animation flow="sequence" duration={1.5s} overflow={clipping}>
        {item.shift(rise, duration=1s, ease="linear")}
        {item.shift(fall, duration=1s, ease="linear")}
    </Animation>
}

<Animation>
    {caption(-33%, "Fill time")}
    {caption(-11%, "Start early")}
    {caption(11%, "Clip")}
    {caption(33%, "Overflow")}
    {blue}{purple}{orange}{green}
</Animation>

<Animation duration={3s} padding={250ms}>
    <Animation duration="match_parent" target={blue}>
        <MoveTo to={Curve(points=[[-33%, 18%], [-33%, -28%], [-33%, 18%]])}
            duration="match_parent" ease="linear" />
    </Animation>
    <Animation flow="sequence" padding_start={250ms} gap={150ms}>
        <Animation offset={-250ms}>
            {purple.shift(rise, duration=750ms, ease="linear")}
        </Animation>
        {purple.shift(fall, duration=750ms, ease="linear")}
    </Animation>
    {round_trip(orange, "hidden")}
    {round_trip(green, "visible")}
</Animation>

Reuse and repeat a plan

Assign an Animation to a variable or return it from a function, then place it where you want it to play. The demo’s bob returns a sequence. bob(green, 350ms).repeat(4) plays it four times alongside the other objects. Use .repeat(forever) for a positive, finite cycle that keeps running. A fixed enclosing window can clip an indefinite loop. Use wait(forever) to hold the current frame indefinitely.

Animation methods

Call these methods on an element or a list of elements. An action shows its target when it starts. Show a visual earlier by placing its name or XML directly in the script or as a child of an Animation. Set duration and ease as needed. The default duration is 300ms. Motion defaults to "spring", and fade, fill, and reveal default to "smootherstep".

MethodEffect
move_to([x, y]), shift([dx, dy])Set a position or add an offset. Use lengths or percentages.
rotate_to(angle), scale_to(number)Rotate or scale. A Box rotates around the center of its resolved layout rectangle.
fill_to(color)Change the fill.
fade_in(), fade_out()Animate opacity.
create(), uncreate()Draw or erase a vector outline.
write(), unwrite()Trace and fill or erase an outline.
grow_from_center(), shrink_to_center()Scale a fixed-size, centered, unrotated element.
expand_x(origin=50%), stretch_x_to(number, origin=50%)Reveal or scale horizontally from an origin.

Use animate(input, to=value, duration=1s) to change a signal input. Pass curve= to animate through keyframes.

Visual checks

Use assert(inside_canvas(card), at=1s) to catch an offscreen element. Other relations include above, below, left_of, right_of, contains, overlaps, disjoint, and touches. For example, always(one.above(two)) tests the whole animation.