I'm writing code to draw squares along the circumference of a circle. I am trying to get the squares to align properly, not rotate arbitrarily. However, nothing seems to work. How do I fix this code? I have tried multiple methods, but this is what I could come up with. I also tried an alternative method wherein no centre is defined; in other words, we start drawing the circle from the circumference (and the alignment there was good). However for the next part of the question, where we have to draw concentric circles, not having a centre runs into trouble.
t.speed(0)
t.width(3)
turtle.bgcolor("grey")
def drawSquare(t, size,color):
for i in range (0,4):
t.forward(size)
t.right(90)
def drawCircle(t,size, n):
t.penup()
t.setpos(0,0)
t.dot(4)
t.right(90)
t.goto(t.pos()+(0,10))
t.penup()
angle=360/n
for i in range(n):
current=i
t.penup()
t.setpos(0,0)
t.penup()
t.forward(50)
t.left(angle)
t.pendown()
parity= (current) % 2
print (parity)
if parity == 0 :
color=t.color("white")
size=30
drawSquare(t, size,color)
t.penup()
t.forward(30)
t.pendown()
else:
color=t.color("black")
size=30
drawSquare(t, size,color)
t.penup()
t.forward(30)
t.pendown()
size=30
n=10
drawCircle(t,size,n)
turtle.done()
main()