Created
September 18, 2015 03:27
-
-
Save schie/aa6bdc8340b8e74d1d41 to your computer and use it in GitHub Desktop.
Example of using turtle, python's built-in graphics module
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
# Example of using turtle, python's built-in graphics module | |
# import turtle with a new name | |
# who wants to write out t-u-r-t-l-e that many times? | |
import turtle as t | |
t.speed(5) # speed | |
t.pensize(5) # thickness | |
# convenience method for drawing circles | |
def make_circle(color, x, y, radius): | |
t.color(color) # set color | |
t.penup() # pick pen up (to not draw) | |
t.goto(x, y) # move pen | |
t.pendown() # put pen down (to allow drawing) | |
t.circle(radius) # draw a circle, yo | |
# Made a convenience function for a convenience function | |
# which was an inconvenience for me to make | |
def make_circle(color, x, y): | |
make_circle(color, x, y, 45) | |
# make some rad circles | |
make_circle("blue", -110, -25) | |
make_circle("black", 0, -25) | |
make_circle("red", 110, -25) | |
make_circle("yellow", -55, -75) | |
make_circle("green", 55, -75) | |
t.done() # this is added to keep the window open until the user exits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment