Skip to content

Instantly share code, notes, and snippets.

@justvanrossum
Last active August 29, 2021 12:18
Show Gist options
  • Save justvanrossum/3312ace9275ad82598d977f15fedb96d to your computer and use it in GitHub Desktop.
Save justvanrossum/3312ace9275ad82598d977f15fedb96d to your computer and use it in GitHub Desktop.
Animated tribute to a work by Herbert W. Kapitzki (DrawBot script)
# Based on a work by Herbert W. Kapitzki
# https://twitter.com/Lett_Arc/status/1369712193063780352
# from fontTools.misc.vector import Vector
from fontTools.misc.arrayTools import Vector
def pairs(iterable):
it = iter(iterable)
first = next(it)
for second in it:
yield first, second
first = second
def interPoint(f, p1, p2):
return p1 + f * (p2 - p1)
def genCorners(corners, centerPoint, numSteps):
for i in range(numSteps):
f = i / (numSteps - 1)
yield [interPoint(f, pt, centerPoint) for pt in corners]
canvasSize = 1000
corners = [Vector(c) * canvasSize for c in [(0, 0), (0, 1), (1, 1), (1, 0)]]
steps = [15, 10, 7, 3, 8]
numSteps = sum(steps)
directions = []
d = 1
for s in steps[:-1]:
directions.extend([d] * s)
d = 1 - d
directions.extend([None] * steps[-1])
numFrames = 200
radius = 250
for frame in range(numFrames):
newPage(canvasSize, canvasSize)
frameDuration(1/30)
fill(1)
rect(0, 0, canvasSize, canvasSize)
angle = tau * frame / numFrames
cx = radius * cos(angle)
cy = radius * sin(angle)
centerPoint = Vector((cx + canvasSize / 2, cy + canvasSize / 2))
stroke(0)
fill(None)
fill(0)
stroke(None)
for i, (pts1, pts2) in enumerate(pairs(genCorners(corners, centerPoint, numSteps))):
d = directions[i]
if d is not None:
for i in range(4):
polygon(pts1[i-1], pts1[i], pts2[i-d])
else:
polygon(*pts1)
saveImage("~/Desktop/Kapitzki.mp4")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment