I'm reading through this blog post, which is about creating cool vector animations in Python using the libraries gizeh and moviepy, neither of which have any hope of working in pythonista. That said, many of the same effects can be achieved in pythonista using images2gif and PIL. I've achieved a good result with the first example I tried to convert.
Their code:
import numpy as np
import gizeh
import moviepy.editor as mpy
W,H = 128,128
duration = 2
ncircles = 20 # Number of circles
def make_frame(t):
surface = gizeh.Surface(W,H)
for i in range(ncircles):
angle = 2*np.pi*(1.0*i/ncircles+t/duration)
center = W*( 0.5+ gizeh.polar2cart(0.1,angle))
circle = gizeh.circle(r= W*(1.0-1.0*i/ncircles),
xy= center, fill= (i%2,i%2,i%2))
circle.draw(surface)
return surface.get_npimage()
clip = mpy.VideoClip(make_frame, duration=duration)
clip.write_gif("circles.gif",fps=15, opt="OptimizePlus", fuzz=10)
outputs

And my code:
# coding: utf-8
import numpy as np
from PIL import Image, ImageDraw
from images2gif import writeGif
from math import sin,cos
W,H = 128,128
duration = 2
ncircles = 20 # Number of circles
def polar2cart(r,theta):
x = r*cos(theta)
y = r*sin(theta)
return x, y
def make_frame(t):
im = Image.new('RGB', (W,H), (0,0,0))
surface = ImageDraw.Draw(im)
for i in range(ncircles):
angle = 2*np.pi*(1.0*i/ncircles+t/duration)
center = W*( 0.5 + polar2cart(0.1,angle)[0]), W*( 0.5 + polar2cart(0.1,angle)[1])
r = W*(1.0-1.0*i/ncircles)
bbox = (center[0]-r, center[1]-r, center[0]+r, center[1]+r)
surface.ellipse(bbox, fill= (i%2*255,i%2*255,i%2*255))
del surface
return im
images = []
for x in range(200):
images.append(make_frame(x/25.0))
writeGif('tunnelswirl.gif',images,0.005)
outputs

Ok, so theirs is prettier because it's vector art and mine is a 128x128 PIL image, but I achieved the same effect. My code is (very heavily) based off of theirs, but it wasn't easy for me to do. I can achieve slightly cleaner results from PIL if I generate frames at 1024x1024, then resize to 128,128. I use this technique whenever I do font rendering with PIL. It would also be interesting to do this with the canvas module, which is for vector graphics.
It also works with more circles





