← circus

Animation Helper

Animation design made easier

Python Code


from svan2d import animation
from svan2d.component import TextRenderer, TextState
from svan2d.converter.converter_type import ConverterType
from svan2d.core.logger import configure_logging
from svan2d.velement import VElement
from svan2d.vscene import VScene
from svan2d.vscene.vscene_exporter import VSceneExporter
from svan2d.core.color import Color

configure_logging(level="INFO")

START_COLOR = Color("#FDBE02")
END_COLOR = Color("#AA0000")


def main():

    # Create the scene
    scene = VScene(width=256, height=256, background=Color("#000017"))

    # Create text states for each number with consistent styling
    # These states will be the starting point of the animation
    states = [
        TextState(
            text=text,
            font_family="Courier New",
            font_size=42,
        )
        for text in ["Empty", "Mirror"]
    ]

    fade_keyframes = animation.atomic.fade(
        states[0], states[1], at_time=0.5, duration=0.4, extend_timeline=True
    )

    renderer = TextRenderer()

    element = VElement(
        renderer=renderer,
        keystates=fade_keyframes,
        attribute_keystates={
            "fill_color": [
                (0, START_COLOR),
                (1, END_COLOR),
            ],
        },
    )

    scene.add_element(element)

    # Create the exporter
    exporter = VSceneExporter(
        scene=scene,
        converter=ConverterType.PLAYWRIGHT,
        output_dir="output/",
    )

    # Export to mp4
    exporter.to_mp4(
        filename="animation_helper",
        total_frames=150,
        framerate=30,
        png_width_px=1024,
    )


if __name__ == "__main__":
    main()



Remarks

  • Animation helpers don’t introduce anything new but provide a growing set of tools for creating keyframe sequences of common animation tasks.
  • svan2d provides two types of animation helpers: atomic, which generate keystates for a single element, and compound, which generate coordinated keystates for multiple elements. These helper can be found in the svan2d.animation module.