Skip to content

Instantly share code, notes, and snippets.

@justvanrossum
Last active October 25, 2021 02:30
Show Gist options
  • Save justvanrossum/bde7e9b5ae5f9b67dd52 to your computer and use it in GitHub Desktop.
Save justvanrossum/bde7e9b5ae5f9b67dd52 to your computer and use it in GitHub Desktop.
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