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

simple polygon-drawing turtle functions

import time

def square1(turtle):
  for i in range(4):
    turtle.forward(100)
    turtle.turn(90)
    time.sleep(1.0)

def triangle1(turtle):
  for i in range(3):
    turtle.forward(100)
    turtle.turn(120)
    time.sleep(1.0)

def polygon(turtle, n, length):
  for i in range(n):
    turtle.forward(length)
    turtle.turn(360/n)

def triangle(turtle):
  polygon(turtle, 3, 100)

def square(turtle):
  polygon(turtle, 4, 100)

# Question (difficult):
# Why does the following not draw a circle?
# (Or at least a 360-sided polygon?)
def circle(turtle):
  polygon(turtle, 360, 1)  


Link to this Page