(Python 3.5.1) In this programming assignment, you will implement 2 drawing func
ID: 3692578 • Letter: #
Question
(Python 3.5.1) In this programming assignment, you will implement 2 drawing functions using turtle module. Function names and parameter properties must be as specified.
1) An n-corner Spiral of Theodorus with side d, for n = 2, 3, 4, .., etc. The function name: drawTheo(myTurtle, n, d)
2) Concentric n circles, centered at (0,0) with radii n*d, for n = 1, 2, 3, .., etc. The function name: drawCirc(myTurtle, n, d)
1)To test your drawTheo function, run your module and then type the following into the shell:
>>> amy = turtle.Turtle()
>>> drawTheo(amy, 5, 50)
2) To test your drawCirc function, run your module and then type the following into the shell:
>>> amy = turtle.Turtle()
>>> drawCirc(amy, 5, 10)
Explanation / Answer
Python Pragram:
1)An n-corner Spiral of Theodorus with side d,
Program:
def drawTheo(myTurtle, n, d):
import math
myTurtle.pu()
myTurtle.home()
myTurtle.pd()
myTurtle.fd(d)
myTurtle.lt(90)
myTurtle.fd(d)
myTurtle.lt(45)
for i in range(n-1):
a = (i+2)
c = math.fabs(math.sqrt(a))
angle = math.degrees(math.atan(c/1))
angle2 = math.degrees(math.atan(1/math.sqrt(a+1)))
angle3 = math.degrees(math.atan(math.sqrt(a+1)/1))
angle4 = 180 - (angle2 + angle3)
angle5 = 180 -(angle + angle4)
myTurtle.fd(d)
myTurtle.lt(angle5)
import turtle
amy = turtle.Turtle()
drawTheo(amy, 5, 50)
2) Concentric n circles, centered at (0,0) with radii n*d,
def drawCirc(myTurtle,n,d):
for i in range(0,n+1,d):
for i in range(n):
drawCircle(myTurtle,d)
myTurtle.up()
myTurtle.left(90)
myTurtle.forward(d)
myTurtle.right(90)
myTurtle.down()
return
import turtle
amy = turtle.Turtle()
drawCirc(amy, 50, 10)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.