Creates a GIF of a bouncing ball:
from PIL import Image, ImageDraw
import imageio
-HEIGHT, R = 126, 10
+WIDTH, R = 126, 10
frames = []
for velocity in range(15):
y = sum(range(velocity+1))
- frame = Image.new('L', (HEIGHT, HEIGHT))
+ frame = Image.new('L', (WIDTH, WIDTH))
draw = ImageDraw.Draw(frame)
- draw.ellipse((HEIGHT/2-R, y, HEIGHT/2+R, y+2*R), fill='white')
+ draw.ellipse((WIDTH/2-R, y, WIDTH/2+R, y+2*R), fill='white')
frames.append(frame)
frames += reversed(frames[1:-1])
imageio.mimsave('test.gif', frames, duration=0.03)