60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
# python-based animation software
|
|
|
|
# describe an animation using python code then render it to a video, gif, etc
|
|
|
|
# tl;dr we draw PNGs and assemble them with ffmpeg
|
|
|
|
# data model:
|
|
# source - input media such as a still image or a video
|
|
# sprite - an instance of a source's media
|
|
|
|
# animation - description of how a source is used in the video
|
|
|
|
|
|
# example video of the dvd bounce logo
|
|
|
|
from pyanimate import Video, \
|
|
Source, ImageSource, \
|
|
Sprite, ImageSprite, \
|
|
Animation, ShowAnimation, HideAnimation
|
|
|
|
|
|
# the video is the canvas that we'll animate objects on top of
|
|
video = Video(framerate=30, width=640, height=480)
|
|
|
|
# a Source is a piece of media that we can include in the animation
|
|
# there should not be any reason to create two Source()s of the same input media.
|
|
logo_img = ImageSource("dvd.png")
|
|
|
|
# a Sprite is an instance of a piece of media. They contain contextual information such as the position of the sprite
|
|
# on the canvas.
|
|
logo = ImageSprite(logo_img) #, position=(0, 0))
|
|
|
|
|
|
# now the sprite appears at 0,0
|
|
video.add_sprite(logo)
|
|
|
|
|
|
# Animations are things that happen to sprites. Sprites are hidden by default so you need a ShowAnimation() to
|
|
# make them visible
|
|
logo.add_animation(ShowAnimation())
|
|
|
|
# Now lets make the logo move. In this case, we just move it diagonally
|
|
# logo_bounce_1 = Animation(
|
|
# # path=xxx,
|
|
# # filters=xxx,
|
|
# # transforms=xxx,
|
|
# # ...
|
|
# after=None,
|
|
# )
|
|
|
|
# Animations are added to sprites. When the video is rendered, animations are applied to the sprite in each frame.
|
|
# Animations begin on frame 0 by default, unless they are delayed by setting a start frame=... or after=....
|
|
# logo.add_animation(logo_bounce_1)
|
|
|
|
|
|
# output the final thing
|
|
video.render("output.mp4")
|
|
# video.render("output.gif")
|
|
|