# Helene Martin, Garfield High School # So far, we have been using functions to create programs. # This script introduces a new programming paradigm: object oriented programming. # Objects are constructs that contain state and behavior: variables and methods. # Turtle objects have methods very similar to the functions we used earlier. # Play around until you are comfortable with this new way of programming! from turtle import * from random import * # clears the screen Screen().clear() # Creates a new turtle instance called bob bob = Turtle() # Makes bob move forward 100 pixels bob.forward(100) # Creates a new turtle called janet shaped like a turtle janet = Turtle(shape="turtle") # Make Janet fat janet.shapesize(4) janet.up() janet.goto(100,100) # When the user clicks and drags janet, she follows the cursor janet.ondrag(janet.goto) turtle_list = [] for i in range(10): # add a turtle to the list turtle_list.append(Turtle('circle')) turtle_list[i].up() # make the turtle go somewhere random turtle_list[i].goto(randint(-200, 200), randint(-200, 200)) # give the turtle a random color turtle_list[i].color(random(), random(), random()) # Do this forever while(True): # For each turtle for t in turtle_list: if(janet.distance(t) < 20): t.stamp() # go to a random location t.goto(randint(-200, 200), randint(-200, 200))