Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a simple animation with Python in DrawBot
# This script is part of a tutorial screencast: https://vimeo.com/149247423
CANVAS = 500
SQUARESIZE = 158
NSQUARES = 50
SQUAREDIST = 6
width = NSQUARES * SQUAREDIST
NFRAMES = 50
for frame in range(NFRAMES):
newPage(CANVAS, CANVAS)
frameDuration(1/20)
fill(0)
rect(0, 0, CANVAS, CANVAS)
phase = 2 * pi * frame / NFRAMES # angle in radians
startAngle = 90 * sin(phase)
endAngle = 90 * sin(phase + 0.5 * pi)
translate(CANVAS/2 - width / 2, CANVAS/2)
fill(1)
stroke(0)
for i in range(NSQUARES + 1):
f = i / NSQUARES
save()
translate(i * SQUAREDIST, 0)
scale(0.7, 1)
rotate(startAngle + f * (endAngle - startAngle))
rect(-SQUARESIZE/2, -SQUARESIZE/2, SQUARESIZE, SQUARESIZE)
restore()
saveImage("StackOfSquares.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.