Skip to content
Shekhar Dutta edited this page Nov 12, 2023 · 2 revisions

Animator

Animator is a Python library that allows you to easily create 2D animations and visualizations. I started this as a hobby project a long time back to learn more about Python and graphics programming. I've went through many iterations of this project, but I think I'll stick with this one for a while. I'm still working on the actual animation part in this version, but you can create some simple animations still.

Animator uses Skia as its graphics backend, so it's fast and supports a wide range of platforms. I used to use skia-python for this project, but I decided to create my own bindings for Skia to make it easier to add new features and fix bugs. The earlier versions of Animator even used pycairo as the graphics backend, but I switched to Skia since it provides more features.

Installation

Installation is kind of a pain right now. I'll work on making it easier. You'll need to build Skia from source and then install Animator using pip. Clone this repository. Visit the Skia website to download and build Skia.

Current Skia commit used: bd56a010b6941116cd1900276bf5201f9a9c73da

These are the basic steps I use to build:

export PATH="${PWD}/depot_tools:${PATH}"
cd skia
python3 tools/git-sync-deps
bin/gn gen out/StaticMin --args='is_debug=false is_official_build=true skia_enable_tools=true skia_use_system_harfbuzz=false skia_use_system_libjpeg_turbo=false skia_use_system_libwebp=false skia_use_libfuzzer_defaults=false skia_use_gl=false text_tests_enabled=false skia_enable_pdf=false skia_enable_gpu=false skia_use_dng_sdk=false skia_enable_fontmgr_android=false skia_enable_discrete_gpu=false skia_build_fuzzers=false paragraph_tests_enabled=false cc="clang-17" cxx="clang++-17" extra_cflags_cc=["-frtti","-mavx"] extra_ldflags=["-lrt"]'
ninja -C out/StaticMin/

Explanation of some build flags

  • extra_cflags_cc=["-frtti","-mavx"]: Enable RTTI for pybind11, and AVX for speedup.
  • skia_enable_fontmgr_android=false: Not building for Android.
  • skia_enable_pdf=false: No PDF support.
  • skia_use_dng_sdk=false: No DNG support, whatever that is.
  • skia_use_gl=false: Disable OpenGL. No GPU support in Animator yet.
  • skia_use_system_harfbuzz=false: Use Skia's internal HarfBuzz library. I didn't have the system HarfBuzz library installed, so I had to use Skia's internal one. You might not need this flag or need similar flags for other libraries.
  • text_tests_enabled=false: Disable tests.

After running ninja, you should have some *.a (or your platform's equivalent) files in out/StaticMin. These includes libharfbuzz.a, libpathkit.a, libskcms.a, libskia.a, libskparagraph.a, libskshaper.a, libsktext.a, libskunicode.a, libsvg.a. They might be different depending on the build flags you used. Copy these files to animator/skia/lib. Required header files are already included.

After this, you can build and install Animator using pip:

pip setup.py install

Getting Started

Here's a quick example to help you get started with Animator:

import animator as am

scene = am.Scene()
scene.add(am.Circle(100))
scene.play_frames()

Output

A yellow circle with blue stroke on a black background.

There are more examples in the examples directory. Start with the Scene next.

Testing

No tests. Animator is a visual library, so tests are visual! I'll add some tests later.

Contributing

Contributions to Animator are welcome! If you find any bugs, have feature requests, or want to contribute code, please open an issue or pull request.

License

Why is licensing so complicated? I'm not a lawyer, so I'll try to explain this as best as I can. Animator is licensed under the MIT License. However, Skia is licensed under the BSD 3-Clause "New" or "Revised" License. This means that you can use Animator for any purpose, but you must include the Skia license too.

Clone this wiki locally