Reputation: 326
So I am trying to teach myself how to code using interactivepython.com
this is one of the exercises...
I have this so far:
import turtle
window = turtle.Screen()
window.bgcolor("lightgreen")
brandon = turtle.Turtle()
brandon.fillcolor('blue')
brandon.pencolor('blue')
brandon.pensize(3)
def drawsq(t, s):
for i in range(4):
t.forward(s)
t.left(90)
for i in range(1,180):
brandon.left(360/i)
drawsq(brandon, 50)
I have tried different ways of rotating the square, but I have not done it correctly. To me this looks like a square rotated x amount of times, right? Could someone please explain this to me?
Thank you!
I keep coming up with something like this
Upvotes: 1
Views: 8162
Reputation: 104712
I think the issue has to do with how much you are rotating by. In your loop, you keep picking different angles to rotate each square. But those aren't angles from a fixed starting position, but rather from the position of the last rotation. This results in a bunch of squares at seemingly random orientations.
Try making your loop something like:
for _ in range(20): # value is not used, it is not an angle, but the number of squares
brandon.left(18) # pick some fixed angle to turn by
drawsq(brandon, 50)
Upvotes: 3