Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified swampy-package/swampy/Gui.pyc
Binary file not shown.
Binary file modified swampy-package/swampy/TurtleWorld.pyc
Binary file not shown.
28 changes: 14 additions & 14 deletions swampy-package/swampy/World.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@

class World(Gui):
"""Represents the environment where Animals live.
A World usually includes a canvas, where animals are drawn,

A World usually includes a canvas, where animals are drawn,
and sometimes a control panel.
"""
current_world = None

def __init__(self, delay=0.5, *args, **kwds):
def __init__(self, delay=0.0, *args, **kwds):
Gui.__init__(self, *args, **kwds)
self.delay = delay
self.title('World')

# keep track of the most recent world
World.current_world = self

# set to False when the user presses quit.
self.exists = True
self.exists = True

# list of animals that live in this world.
self.animals = []
Expand All @@ -53,7 +53,7 @@ def quit(self):

# destroy closes the window
self.destroy()

# quit terminates mainloop (but since mainloop can get called
# recursively, quitting once might not be enough!)
Gui.quit(self)
Expand Down Expand Up @@ -104,7 +104,7 @@ def step(self):
"""Invoke the step method on every animal."""
for animal in self.animals:
animal.step()

def run(self):
"""Invoke step intermittently until the user presses Quit or Stop."""
self.running = True
Expand All @@ -126,11 +126,11 @@ def map_animals(self, callable):

def make_interpreter(self, gs=None):
"""Makes an interpreter for this world.

Creates an attribute named inter.
"""
self.inter = Interpreter(self, gs)

def run_text(self):
"""Executes the code from the TextEntry in the control panel.

Expand All @@ -141,7 +141,7 @@ def run_text(self):

def run_file(self):
"""Read the code from the filename in the entry and runs it.

Precondition: self must have an Interpreter and a filename entry.
"""
filename = self.en_file.get()
Expand All @@ -160,11 +160,11 @@ def __init__(self, world, gs=None):
self.globals = globals()
else:
self.globals = gs

def run_code_thread(self, *args):
"""Runs the given code in a new thread."""
return MyThread(self.run_code, *args)

def run_code(self, source, filename):
"""Runs the given code in the saved environment."""
code = compile(source, filename, 'exec')
Expand Down Expand Up @@ -250,7 +250,7 @@ def redraw(self):

def polar(self, x, y, r, theta):
"""Converts polar coordinates to cartesian.

Args:
x, y: location of the origin
r: radius
Expand All @@ -262,7 +262,7 @@ def polar(self, x, y, r, theta):
rad = theta * math.pi/180
s = math.sin(rad)
c = math.cos(rad)
return [ x + r * c, y + r * s ]
return [ x + r * c, y + r * s ]


def wait_for_user():
Expand Down
Binary file modified swampy-package/swampy/World.pyc
Binary file not shown.
34 changes: 23 additions & 11 deletions swampy-package/swampy/sib_answers.txt
Original file line number Diff line number Diff line change
@@ -1,45 +1,57 @@
# Text answers from Week 0

# Name:
# Name: Elizabeth Tenorio



Explain what each of the following lines does. Use the terminology you learned from the book (or Google)

from TurtleWorld import *
world = TurtleWorld()
bob = Turtle()
wait_for_user()

Answer:



Line 1 imports all functions from the module TurtleWorld which allows the functions to be called without using dot notation.
Line 2 creates a TurtleWorld assigned to world.
Line 3 creates "bob", an an instance of a Turtle as defined in module TurtleWorld.
Line 4 tells TurtleWorld to wait for the user to do something.



These questions pertain to the program you wrote in Week0.

-- What are the arguments of polygon()? What type is each argument?
Answer:
Answer: The arguments and their types are:
turtle (object of class turtle.Turtle), length (positive number, int), and number of sides "n" (positive int)

-- What two turtle functions did you use to draw the sides of the polygon?
Answer:

-- What are the arguments for polyline? What type is each argument?
Answer:
Answer: fd() and lt()


-- What are the arguments for polyline? What type is each argument?
Answer:The arguments and their types are:
turtle(object of class turtle.Turtle), length (positive number, int), angle (positive number, float), and number of sides "n" (positive number, int)



Suppose you wrote a function, center_circle(), that draws a circle of a given radius around the current location of the turtle and restores the turtle to its starting point.

-- What turtle functions would you use to move the turtle from the center to the edge of the circle and get ready to call the original circle() function?
Answer:
pu(bob)
fd(bob, radius)
lt(bob)
pd(bob)


-- Suppose the interface of this function requires the turtle to end up in the same place it started, facing in the same direction it started.
Answer:
pu(bob)
lt(bob)
fd(bob, radius)
lt(bob, 180)
pd(bob)

-- What is this type of requirement called?
Answer:
Answer: postcondition
Binary file added swampy-package/swampy/sib_flower.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 40 additions & 6 deletions swampy-package/swampy/sib_flower.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,56 @@
# Flower excercise (4.2) from Week 0

# Name:
# Name: Elizabeth Tenorio

import math
from TurtleWorld import *
world = TurtleWorld()
bob = Turtle()

from TurtleWorld import *
world = TurtleWorld()
bob = Turtle()
# This is where you put code to move bob

def polyline(turtle, length, angle, n):
for i in range(n):
fd(turtle, length)
lt(turtle, angle)
#polyline(bob, 50, 20, 5)

def arc(turtle, radius, theta):
circumference = 2 * 3.1416 * radius
arc_length = radius * math.radians(theta)
n = int(circumference / 3) + 1
step_length = arc_length / n
step_angle = float(theta) / n
polyline(turtle, step_length, step_angle, n)

#arc(bob, 50, 100)

# This is where you put code to move bob

def petal(turtle, radius, angle):
for i in range(2):
arc(turtle, radius, angle)
lt(turtle, 180 - angle)

#petal(bob, 100, 80)
def flower(turtle, p, radius, angle):
for i in range(p):
petal(turtle, radius, angle)
lt(turtle, 360.0/p)

def position(turtle, length):
pu(turtle)
fd(turtle, length)
pd(turtle)

position(bob, -100)
flower(bob, 7, 80.0, 60.0)

position(bob, 180)
flower(bob, 10, 60.0, 80.0)

position(bob, 180)
flower(bob, 20, 120.0, 20.0)


wait_for_user()
wait_for_user()

Binary file added swampy-package/swampy/sib_hello.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 83 additions & 5 deletions swampy-package/swampy/sib_hello.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,99 @@
# Hello excercise from Week 0

# Name:
# Name: Elizabeth Tenorio


from TurtleWorld import *
world = TurtleWorld()
bob = Turtle()
from TurtleWorld import *
world = TurtleWorld()
bob = Turtle()



# This is where you put code to move bob
#move to position
def start_pos(turtle):
pu(turtle)
lt(turtle)
fd(turtle, 20)
lt(turtle)
fd(turtle, 160)
pd(turtle)

#write H
def write_h(turtle):
lt(turtle)
fd(turtle, 80)
bk(turtle, 40)
lt(turtle)
fd(turtle, 40)
lt(turtle)
fd(turtle, 40)
lt(turtle)
lt(turtle)
fd(turtle, 80)

#move to start of letter E
def letter_pos_e(turtle):
pu(turtle)
lt(turtle)
fd(turtle, 20)
lt(turtle)
fd(turtle, 80)
pd(turtle)

#move to start of letter
def letter_pos(turtle):
pu(bob)
fd(bob, 20)
lt(bob)
fd(bob, 80)
lt(bob)
lt(bob)
pd(bob)

#write E
def write_e(turtle):
rt(turtle)
fd(turtle, 40)
bk(turtle, 40)
rt(turtle)
fd(turtle, 40)
lt(turtle)
fd(turtle, 40)
bk(turtle, 40)
rt(turtle)
fd(turtle, 40)
lt(turtle)
fd(turtle, 40)

#write L
def write_l(turtle):
fd(turtle, 80)
lt(turtle)
fd(turtle, 40)

#write O
def write_o(turtle):
fd(turtle, 80)
lt(turtle)
fd(turtle, 40)
lt(turtle)
fd(turtle, 80)
lt(turtle)
fd(turtle, 40)

start_pos(bob)
write_h(bob)
letter_pos_e(bob)
write_e(bob)
letter_pos(bob)
write_l(bob)
letter_pos(bob)
write_l(bob)
letter_pos(bob)
write_o(bob)

wait_for_user()



wait_for_user()
Loading