Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DrawBot: create a simple animation with moving squares
# http://dailydrawbot.tumblr.com/post/163234641179/nested-boxes
def easeInOutQuad(t):
t *= 2
if t < 1:
return 0.5 * (t ** 2)
else:
t = 2 - t
return 1 - 0.5 * (t ** 2)
canvasSize = 600
strokeThickness = 30
numFramesPerSide = 10
for side in range(4):
for frame in range(numFramesPerSide):
t = easeInOutQuad(frame / numFramesPerSide)
newPage(canvasSize, canvasSize)
frameDuration(1/20)
fill(1)
rect(0, 0, canvasSize, canvasSize)
fill(None)
stroke(0)
strokeWidth(1 * strokeThickness)
x, y = 0, 0
sqSize = canvasSize
for i in range(7):
rect(x + strokeThickness/2, y + strokeThickness/2, sqSize - strokeThickness, sqSize - strokeThickness)
if side == 0:
dx = 1 + t
dy = 1
elif side == 1:
dx = 2
dy = 1 + t
elif side == 2:
dx = 2 - t
dy = 2
elif side == 3:
dx = 1
dy = 2 - t
x += dx * strokeThickness
y += dy * strokeThickness
sqSize -= 3 * strokeThickness
saveImage("NestedBoxes.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.