Skip to content

Instantly share code, notes, and snippets.

@alphamikevictor
Created April 7, 2018 05:16
Show Gist options
  • Select an option

  • Save alphamikevictor/556c57dc86f9286eaacea7ac3083c651 to your computer and use it in GitHub Desktop.

Select an option

Save alphamikevictor/556c57dc86f9286eaacea7ac3083c651 to your computer and use it in GitHub Desktop.
Python draw polygons using turtle
import turtle
def polygon(vertices,pixels=50,clockwise=True):
tt = (turtle.left,turtle.right)[clockwise]
if not isinstance(vertices,int):
raise TypeError("I need an Integer for vertices")
if vertices < 3:
raise ValueError("Vertices al menos ha de valer 3")
if not isinstance(pixels,int):
raise TypeError("I need pixels as integer")
for angle in range(vertices):
turtle.forward(pixels)
tt(360/vertices)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment