Skip to content

Instantly share code, notes, and snippets.

@justvanrossum
Last active December 13, 2017 17:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justvanrossum/7708517c9da45eb0bc79e2e1c01d6ffa to your computer and use it in GitHub Desktop.
Save justvanrossum/7708517c9da45eb0bc79e2e1c01d6ffa to your computer and use it in GitHub Desktop.
DrawBot: infinite zoom into a Sierpinski Square (takes a while to render!)
# Slightly modified from
# https://twitter.com/petrvanblokland/status/860610270410018817
# by Petr van Blokland @petrvanblokland
def drawSierpinskiSquare(px, py, w, maxW, maxH):
if w < 1:
return
for x in range(3):
for y in range(3):
if x == 1 and y == 1:
fill(max(0, 0.75 - w/100))
rect(px+w, py+w, w, w)
elif px < maxW and py < maxH:
drawSierpinskiSquare(px+x*w, py+y*w, w/3, maxW, maxH)
canvasSize = 500
numFrames = 40
scaleFactor = 3 ** (1/numFrames)
for frame in range(numFrames):
newPage(canvasSize, canvasSize)
frameDuration(1/30) # 30 frames per second
fill(1) # draw a white background
rect(0, 0, canvasSize, canvasSize)
w = canvasSize * (scaleFactor ** frame)
drawSierpinskiSquare(0, 0, w, canvasSize, canvasSize)
saveImage("SierpinskiSquare.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment