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
1 change: 1 addition & 0 deletions swampy-package/swampy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
46 changes: 37 additions & 9 deletions swampy-package/swampy/sib_answers.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Text answers from Week 0

# Name:
# Name: Aarthi Narayan



Expand All @@ -11,7 +11,11 @@ Explain what each of the following lines does. Use the terminology you learned f
bob = Turtle()
wait_for_user()

Answer:
Answer:
The first line imports the module TurtleWorld into this program
The second line assigns world to TurtleWorld()
The third line assigns Turtle() to bob
The fourth informs the module TurtleWorld to wait for the user input.



Expand All @@ -21,25 +25,49 @@ Answer:
These questions pertain to the program you wrote in Week0.

-- What are the arguments of polygon()? What type is each argument?
Answer:
Answer: Turtle,length,n
turtle is class 'TurtleWorld.Turtle'
Length is int
n is also int

-- What two turtle functions did you use to draw the sides of the polygon?
Answer:
Answer: forward : fd(t) and left turn : lt(t)

-- What are the arguments for polyline? What type is each argument?
Answer:

Answer: turtle, no. of segments, length, angle
turtle : Class
no. of seqments or recursions : int
length = int
angle = 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:
Answer:
pu(t)
fd(t,radius)
pd(t)
circle(t,radius=50)

-- 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:
Answer: Enclose the circle in for loop so that the turtle takes an extra turn

def move_turtle(t,radius):
pu(t)
fd(t,radius)
pd(t)

move(bob,radius=50)
circle(t,radius=50)
lt(bob)
move(bob,radius=50)





-- 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.
45 changes: 43 additions & 2 deletions swampy-package/swampy/sib_flower.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,56 @@
# Flower excercise (4.2) from Week 0

# Name:
# Name: Aarthi Narayan


from TurtleWorld import *
world = TurtleWorld()
bob = Turtle()
import math
bob.delay = 0.01

# This is where you put code to move bob


# This is where you put code to move bob
def petal(t,r,angle):
"""create one petal using r as radius and angle as the given angle"""
for i in range(2):
arc(t,r,angle)
lt(t,180-angle)

def flower(t,p,r,angle):
"""create one flower using p as the number of petals and r as radius"""
for i in range(p):
petal(t,r,angle)
lt(t,360/p)

def common_function(t, n, length, angle):
for i in range(n):
fd(t, length)
lt(t, angle)


def arc(t, r,angle):
arc_length = 2 * math.pi * r * angle/360
n = int(arc_length/4) + 1
segment_length = arc_length / n
segment_angle = float(angle) / n
lt(t, segment_angle/2)
common_function(t, n, segment_length, segment_angle)
rt(t, segment_angle/2)

def space(t,distance):
"""defines a space between each flower"""
pu(t)
fd(t,distance)
pd(t)

space(bob,100)
flower(bob,7,60,50)
space(bob,200)
flower(bob,10,40,120)
space(bob,150)
flower(bob,20,80,30)



Expand Down
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.
65 changes: 64 additions & 1 deletion swampy-package/swampy/sib_hello.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Hello excercise from Week 0

# Name:
# Name: Aarthi Narayan


from TurtleWorld import *
Expand All @@ -10,7 +10,70 @@


# This is where you put code to move bob
from TurtleWorld import *

world = TurtleWorld()
bob = Turtle()


fd(bob, 100)
lt(bob)
fd(bob,100)
lt(bob)
pu(bob)
fd(bob,100)
lt(bob)
pd(bob)
fd(bob,200)
lt(bob)
pu(bob)
fd(bob,100)
lt(bob)
pd(bob)
fd(bob,100)
pu(bob)
rt(bob)
fd(bob,100)

pd(bob)
fd(bob,100)
lt(bob)
pu(bob)
fd(bob,100)
lt(bob)
pd(bob)
fd(bob,100)
lt(bob)
fd(bob,200)
lt(bob)
fd(bob,100)
pu(bob)
fd(bob,100)

def_writeL():
pd(bob)
lt(bob)
fd(bob,200)
pu(bob)
bk(bob,200)
pd(bob)
rt(bob)
fd(bob,100)
pu(bob)
fd(bob,100)

def_writeL()
def_writeL()

pd(bob)
fd(bob,100)
lt(bob)
fd(bob,200)
lt(bob)
fd(bob,100)
lt(bob)
fd(bob,200)
wait_for_user()



Expand Down
43 changes: 35 additions & 8 deletions swampy-package/swampy/sib_polygon.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
# Polygon excercise from Week 0

# Name:
# Name: Aarthi Narayan


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

from math import pi


# This is where you put code to move bob






def common_function(t, length, n, theta):
for i in range(n):
fd(bob, length)
lt(bob, 360/n)

def polygon(t, length, n):
common_function(t, length,n)

def square(t, length)
for i in range(4):
fd(t, length)
lt(t)

def circle(t,r):
# length = (2 * pi * r )/n
# n = 50
# theta = 360
# common_function(t, length, n, theta)
arc(t,r,360)

def arc(t, r, theta):
entire_length = (2 * pi * r) * theta/360
n = 50
length = entire_length/n
common_function(t, length, n, theta)

square(bob, 100)

polygon(bob, 20, 8)

circle(bob, 10)

arc(bob, 10, 360)


wait_for_user()