Skip to content

Instantly share code, notes, and snippets.

@justvanrossum
Last active April 29, 2020 16:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justvanrossum/b9b931c25921bdb015f4af87aee9ef68 to your computer and use it in GitHub Desktop.
Save justvanrossum/b9b931c25921bdb015f4af87aee9ef68 to your computer and use it in GitHub Desktop.
DrawBot: create a grid of Lissajous curve variations.
# http://dailydrawbot.tumblr.com/post/160078796339/lissajous-grid
# remade from https://twitter.com/fermatslibrary/status/857580490425020416
def lissajous(a, b, phase, radius):
numSteps = 340
points = []
for i in range(numSteps):
angle = 2 * pi * i / numSteps
x = radius * sin(a * angle + phase)
y = -radius * sin(b * angle)
points.append((x, y))
return points
canvasSize = 500
numFrames = 72
numShapes = 5
gridSize = canvasSize / numShapes
radius = 0.375 * gridSize
for frame in range(numFrames):
t = frame / numFrames
newPage(canvasSize, canvasSize)
frameDuration(1/20)
fill(1)
rect(0, 0, canvasSize, canvasSize)
stroke(0)
strokeWidth(2)
lineJoin("round")
fill(None)
for a in range(1, numShapes + 1):
for b in range(1, numShapes + 1):
save()
translate(gridSize * a - 0.5 * gridSize,
canvasSize - gridSize * b + 0.5 * gridSize)
points = lissajous(b, a, 2 * pi * t, radius)
polygon(*points)
restore()
saveImage("LissajousGrid.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment