Created
May 3, 2016 19:07
-
-
Save justvanrossum/5546cafd3c239623764fe586cebc9811 to your computer and use it in GitHub Desktop.
DrawBot: Create a simple animation with a grid of rotating squares.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://dailydrawbot.tumblr.com/post/143801148619/square-vs-lozenge | |
def rotatedSquare(x, y, squareSize, angle): | |
offsetSin = squareSize * sin(radians(angle)) | |
save() | |
translate(x + offsetSin, 0) | |
rotate(angle) | |
rect(0, 0, squareSize, squareSize) | |
restore() | |
canvasSize = 500 | |
nFrames = 100 | |
squareSize = 56 | |
nSquares = 6 # must be even | |
for frame in range(nFrames): | |
newPage(canvasSize, canvasSize) | |
frameDuration(1/20) | |
fill(0) | |
rect(0, 0, canvasSize, canvasSize) | |
fill(1) | |
stroke(1) | |
strokeWidth(0.1) | |
translate(canvasSize/2, canvasSize/2) | |
angle = (90 * frame / nFrames) | |
offset = squareSize * (sin(radians(angle)) + cos(radians(angle))) | |
translate(-(nSquares//2) * offset, -(nSquares//2) * offset) | |
for j in range(nSquares): | |
save() | |
for i in range(nSquares): | |
rotatedSquare(0, 0, squareSize, angle) | |
translate(offset, 0) | |
angle = 90 - angle | |
restore() | |
translate(0, offset) | |
angle = 90 - angle | |
saveImage("SquareVsLozenge.gif") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment