Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

mystery turtle functions

#After you have worked out on paper what mystery1 through mystery4 do
#Run the test program to find out. Type
# >>>test()
# in the command area. This function creates a new world and turtle each
# time, so none of the mystery functions affect each other.
#
# Supplementary question for understanding (1):
# Say you create a world and a turtle called elliott in it,
# what would the following draw?
# >>>mystery1(elliott)
# >>>mystery2(elliott)
# >>>mystery3(elliott)
# >>>mystery4(elliott)
# Remember that now the finishing location and orientation of elliott in one function
# affects where he goes subsequently.
#
# Supplementary question for understanding (2):
# There is a double vertical line when you do this, even though there should be two lines
# in the same place. Why are they displaced horizontally when they shouldn't be?
# Hint: turtle locations are always integers. Where does going forward a fixed number of
# pixels take a turtle if it is moving in diagonally?

def mystery1(turtle):
  for i in range(4):
    turtle.forward(100)
    turtle.turnRight()

def mystery2(turtle):
  for i in range(3):
    turtle.forward(100)
    turtle.turnRight()

def mystery3(turtle):
  for i in range(3):
    turtle.forward(100)
    turtle.turn(120)

def mystery4(turtle):
  turtle.turnRight()
  for i in range(3):
    turtle.forward(100)
    turtle.turn(120)

# Demonstration program.
# Executes mystery1 through mystery4 five seconds apart.
def test():
  import time
  for i in range(1, 5):
    world = makeWorld()
    t = makeTurtle(world)
    if i == 1:
      mystery1(t)
    elif i == 2:
      mystery2(t)
    elif i == 3:
      mystery3(t)
    else:
      mystery4(t)
    time.sleep(5.0)



Link to this Page