Skip to content

Instantly share code, notes, and snippets.

@justvanrossum
Last active September 16, 2021 06:08
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 justvanrossum/a74eb9c57206b553fc28731c7ff6b8d3 to your computer and use it in GitHub Desktop.
Save justvanrossum/a74eb9c57206b553fc28731c7ff6b8d3 to your computer and use it in GitHub Desktop.
A grid of moving rectangles
# Inspired by:
# https://www.instagram.com/p/_hZD9hn9Xn/
def square(x, y, size, phase):
turns = phase // 2
q = (phase % 2) / 2
with savedState():
translate(x, y)
scale(size)
rotate(-90 * turns, center=(0.5, 0.5))
rect(0, 0, 1 - q, q)
canvasSize = 500
nSquares = 8
squareSize = canvasSize / nSquares
nFrames = 80
for frame in range(nFrames):
framePhase = 8 * frame / nFrames
newPage(canvasSize, canvasSize)
frameDuration(1/20)
rect(0, 0, canvasSize, canvasSize)
fill(1)
for i in range(nSquares):
for j in range(nSquares):
phase = 2 * (i + j) / nSquares + framePhase
x = i * squareSize
y = j * squareSize
square(x, y, squareSize, phase)
saveImage("RectangleGrid.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment