Last active
July 7, 2018 17:44
-
-
Save mathieureguer/4a47b9324674f3b7f98e91de58451d41 to your computer and use it in GitHub Desktop.
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
# HI DAVE! | |
import math | |
canvas = 500 | |
squareSize = 100 | |
startPos = 0 | |
endPos = 400 | |
frameRate = 24 | |
duration = 2000 # in milliseconds | |
frames = int(duration / frameRate) | |
print(frames) | |
for frame in range(frames): | |
pos = -(endPos-startPos)/2 * (math.cos(math.pi*frame/frames*2)-1) | |
newPage(canvas, canvas) | |
frameDuration(1/frameRate) # moving that to after newPage to avoid having a first black frame | |
fill(1) | |
rect(0, 0, width(), height()) | |
save() | |
fill(0,0,0) | |
translate(pos, 0) | |
rect(0, 0, squareSize, squareSize) | |
restore() | |
# page count | |
fill(0) | |
textBox("{}".format(pageCount()), (canvas-220, 20, 200, 20), align="right") | |
saveImage('moving square.gif') | |
#saveImage('moving square.mp4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment