Skip to content

Instantly share code, notes, and snippets.

@nasturtus
Created May 4, 2017 03:06
Show Gist options
  • Save nasturtus/0736a2ed04f211cfd13924a17f0d510f to your computer and use it in GitHub Desktop.
Save nasturtus/0736a2ed04f211cfd13924a17f0d510f to your computer and use it in GitHub Desktop.
# http://greenteapress.com/thinkpython2/html/thinkpython2005.html
import turtle
import math
def polygon(t, n, length):
angle = 360 / n
print(angle)
for i in range(n):
t.fd(length)
t.rt(angle)
# Use polygon to draw a circle
def circle(t, radius):
circumference = 2 * math.pi * radius
print(circumference)
n = int(circumference / 3)
print(n)
length = circumference / n
print(length)
polygon(t, n, length)
bob = turtle.Turtle()
circle(t=bob, radius=100) # keyword arguments for greater readibility
turtle.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment