PilAnimate is a python library that renders video frame by frame, using PIL.
Documentations are up to date for version 0.4.1. A lot of the library is just a wrapper for PIL, so if you are having trouble it could be useful to reference those if you encounter any issues.
I mostly made PilAnimate for my personal use, and I'm sure there's probably better ones out there, but I made PilAnimate to be fairly simple and easily extendable. It renders frame by frame, meaning that even the most complex tasks can be completed on old computers, albeit slowly.
pip install pilanimate
Class
Creates layers
Parameters:
Returns: itself
Properties: layers, fps, mode, size
Function
Turns frames into video.
Parameters:
Returns: Nothing, creates filename+".avi" video
Class
Creates layer. A layer is essentially an array of images. When the video is exporting, the layers will be pasted on each other to create an array of frames (layer 0 is at the bottom).
Warning: Do not create this class yourself, making the Animation
class will do it for you.
Parameters:
Returns: itself
Properties: size, img, layer, fps, frames, mode
Function
Creates a point at coords
Parameters:
Returns: nothing
Function
Creates line, where each array [x,y]
inside coords
is a point, connected in order.
Parameters:
Returns: nothing
Function
Creates arc with starting and ending angles inside the bounding box.
Parameters:
Returns: nothing
Function
Creates ellipse inside bounding box
Parameters:
Returns: nothing
Function
Creates polygon
Parameters:
Returns: nothing
Function
Creates rectangle
Parameters:
Returns: nothing
Function
Creates a rounded rectangle
Parameters:
Returns: nothing
Function
Fills entire layer with color
Parameters:
Returns: nothing
Function
Creates text at coords to layer. Has a kinds of parameters that can be fiddled with, making it a really powerful function.
Parameters:
Returns: nothing
Function
Adds image to layer
Parameters:
((x,y), (x,y))
Returns: nothing
Function
Adds a gif to the layer (this function also creates frames for you, for the number of frames long the gif is * times_to_repeat
frames)
Parameters:
((x,y), (x,y))
Returns: nothing, but appends frames
Function
Rotates layer
Parameters:
Returns: nothing
Function
Move layer
Parameters:
Returns: nothing
Function
Changes opacity (transparency) of the layer, of every non transparent pixel.
Parameters:
Returns: nothing
Function
Changes opacity of entire layer, including transparent pixels, so only use this for layers with no transparent parts
Parameters:
Returns: nothing
Function
Slowly fades in a layer, going from transparent to fully opaque.
Parameters:
Returns: nothing, but appends frames
Function
Slowly fades out a layer, going from fully opaque to fully transparent.
Parameters:
Returns: nothing, but appends frames
Function
Transforms layer. This function is very complicated so and frankly I have no clue what most of thse are, so please refer to PIL Docs for more detail.
Parameters:
Returns: nothing
Function
Blurs layer
Parameters: none
Returns: nothing
Function
Clears area of layer, turning it transparent
Parameters:
((x,y), (x,y))
Function
Clears entire layer, turning it transparent
Parameters: none
Returns: nothing
Function
Adds the layer in its current state to the frames array
Parameters: none
Returns: nothing, but appends a frame
Function
Adds frames without changing the layer
Parameters:
Returns: nothing
Function
Save current layer as a file
Parameters:
Returns: nothing
Function
Make layer slowly rises
Parameters:
Returns: nothing, but appends frames
Function
Make layer slowly descend
Parameters:
Returns: nothing, but appends frames
Function
Makes the layer slide to the side
Parameters:
Returns: nothing, but appends frames
Function
Makes the layer spin
Parameters:
Returns: nothing, but appends frames
Here's a basic example that creates a sun rising from the sea:
from PilAnimate import Animation, ImageColor, Image animation = Animation(3) animation.layers[0].fillAll(fill="SkyBlue") #sun layer animation.layers[1].createEllipse(((700,650),(900,850)), fill="yellow") #ocean layer animation.layers[2].createRectangle(((0, 500),(1600,900)), fill="Blue", width=0) animation.layers[0].doNothing(100) animation.layers[2].doNothing(100) animation.layers[1].rise(100, -501) animation.export()
Example of an extension I made that makes backgrounds:
from PilAnimate import Layer import math class Background(): #remember to add params def __init__(self, layer, background_image): self.background_image = background_image self.layer = layer self.layer.addImage(self.background_image.copy().crop((0,0,self.layer.size[0],self.layer.size[1])), coords=(0, 0, self.layer.size[0], self.layer.size[1])) def pan_down(self, frames, all_the_way=True): #speed is pixels per frame #(background_image height-layer height)/speed # amount = (self.background_image.size[1]-self.layer.size[1])/frames amount = math.floor(amount) for i in range(frames-1): self.layer.addImage(self.background_image.copy().crop((0, i*amount, self.background_image.size[0], i*amount+self.layer.size[1])), coords=(0, 0, self.layer.size[0], self.layer.size[1])) self.layer.saveFrame() if all_the_way: self.layer.addImage(self.background_image.copy().crop((0, (self.background_image.size[1]-self.layer.size[1]), self.background_image.size[0], (self.background_image.size[1]-self.layer.size[1])+self.layer.size[1])), coords=(0, 0, self.layer.size[0], self.layer.size[1])) self.layer.saveFrame()