← circus

Timeline easing

Apply easing to the entire animation timeline

Python Code


from svan2d import (
    CircleState,
    Color,
    ConverterType,
    Point2D,
    SquareState,
    VElement,
    VScene,
    VSceneExporter,
    configure_logging,
    easing,
)


configure_logging(level="INFO")


OUTER_COLOR = Color("#FDBE02")
CENTER_COLOR = Color("#AA0000")


def main():

    # Simple zoom-out with animate_camera()
    scene = VScene(
        width=600,
        height=600,
        timeline_easing=easing.out_bounce,
        background=Color("#000017"),
    )

    # Create circles in a grid pattern
    elements = []
    for i in range(-2, 3):
        for j in range(-2, 3):

            dist = (i**2 + j**2) ** 0.5
            t = dist / (2 * 2**0.5)
            s1 = SquareState(
                size=4,
                pos=Point2D(i * 20, j * 20),
                fill_color=CENTER_COLOR.interpolate(OUTER_COLOR, t),
            )
            s2 = CircleState(
                radius=30,
                pos=Point2D(i * 80, j * 80),
                fill_color=CENTER_COLOR.interpolate(OUTER_COLOR, t),
            )

            elements.append(VElement().keystates([s1, s2]))

    scene = scene.add_elements(elements)

    # Export
    exporter = VSceneExporter(
        scene=scene,
        converter=ConverterType.CAIROSVG,
        output_dir="output/",
    )

    exporter.to_mp4(
        filename="timeline_easing",
        total_frames=90,
        framerate=30,
        png_width_px=1024,
        num_thumbnails=100,
    )


if __name__ == "__main__":
    main()