# Load the turtle module to use functions from it
import turtle
# Create a turtle object called ada
ada = turtle.Turtle()
# Move ada around
ada.goto(100,100)# move to the given (x,y) position
ada.forward(200) # move forward 200 steps (pixels)
ada.right(90) # make 90 degree right turn
ada.forward(50) # move forward 50 steps (pixels)
print("Where is ada? ", ada.position()) # (x,y) coordinates
print("Where is ada headed? ", ada.heading()) # counterclockwise degrees from right / east
ada.right(90)
ada.up() # pick up the pen
ada.forward(150)
ada.down() # put back down the pen
ada.forward(50)
# Define our own function with 'def' and the name of our function
# We pass any number of parameters to our function
# Here, we have two parameters: turtle and hopCount
# All code part of this function must be indented by a tab character
def skipForward(bob, hopCount):
bob.up()
bob.forward(hopCount)
bob.down()
bob.forward(hopCount)
# This code is not indented. It's not part of the function
# We call the function we wrote here and give it arguments
skipForward(ada, 20)
skipForward(ada, 30)
skipForward(ada, 50)
# TO ADD DURING CLASS
def drawTriangle(length):
fred = turtle.Turtle()
fred.forward(length)
fred.right(360/3)
fred.forward(length)
fred.right(360/3)
fred.forward(length)
drawTriangle(100)