Skip to content

Instantly share code, notes, and snippets.

@justinnhli
Last active June 5, 2017 23:07
Show Gist options
  • Save justinnhli/6fe2ec76a7614d7dde5132de08742166 to your computer and use it in GitHub Desktop.
Save justinnhli/6fe2ec76a7614d7dde5132de08742166 to your computer and use it in GitHub Desktop.
Pretty Spirals
from turtle import *
'''
Animated result: http://imgur.com/H49ukwF.gif
This script saves each image as 000.ps, 001.ps, ..., 180.ps
The Postscript files can be converted to jpgs/pngs using imagemagick:
$ convert -density 200 -geometry 50% -flatten 180.ps 180.png
To generate an animated gif, use imagemagick again:
$ convert -delay 1 -loop 0 *.png animation.gif
'''
for angle in range(0, 181):
reset()
speed(9)
left(90)
for length in range(10, 301, 5):
right(angle)
forward(length)
filename = '{:03d}.ps'.format(angle)
with open(filename, 'w') as fd:
fd.write(Screen().getcanvas().postscript())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment