Created
April 7, 2018 05:16
-
-
Save alphamikevictor/556c57dc86f9286eaacea7ac3083c651 to your computer and use it in GitHub Desktop.
Python draw polygons using turtle
This file contains hidden or 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
| 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