Skip to content

Instantly share code, notes, and snippets.

@nedbat
Created November 12, 2017 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nedbat/c9564c4f1aac8c6f588f553c73fb1220 to your computer and use it in GitHub Desktop.
Save nedbat/c9564c4f1aac8c6f588f553c73fb1220 to your computer and use it in GitHub Desktop.
# For Drawbot
import os
canvas_h = 300
canvas_w = canvas_h * 2
n_frames = 40
grid = 10
def new_page():
newPage(canvas_w, canvas_h)
frameDuration(1/20)
fill(0)
rect(0, 0, canvas_w, canvas_h)
newPath()
def draw_grid(xc, yc, grid, rot, extent):
save()
translate(xc, yc)
rotate(rot)
for x in range(-extent, extent, grid):
moveTo((x, -extent))
lineTo((x, extent))
for y in range(-extent, extent, grid):
moveTo((-extent, y))
lineTo((extent, y))
stroke(1)
drawPath()
restore()
def clip_rect(llx, lly, urx, ury):
moveTo((llx, lly))
lineTo((urx, lly))
lineTo((urx, ury))
lineTo((llx, ury))
closePath()
clipPath()
newPath()
half = canvas_h//2
extent = canvas_h
for frame in range(n_frames):
new_page()
rot = frame * 90/n_frames
save()
clip_rect(0, 0, canvas_w//2, canvas_h)
draw_grid(half, half, grid, rot, extent)
restore()
save()
clip_rect(canvas_w//2, 0, canvas_w, canvas_h)
draw_grid(canvas_w//2 + half, half, grid, rot*2, extent)
restore()
name = os.path.splitext(os.path.basename(__file__))[0]
saveImage("~/Downloads/%s.gif" % name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment