Python Forum

Full Version: turtle calculate angles
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Oh my this is so basic but....

I can create a 5 pointed star beautifully using a for loop. I can see different variations of star using while loops, but I want to stay with a for loop for now. I am sharing code from a trinket:

https://trinket.io/python/65aa794032

You will see that the first 2 start work well, and I thought I had the maths / coding principles, but it does not work for all variations. Can anyone see what the problem is?

I have added the code below too in case you don't want to use the trinket:

from turtle import *

star = Turtle()
screen = Screen()
screen.bgcolor("blue")
star.speed(5)
star.pu()
star.goto(-75,0)
star.pd()

#star

star.pencolor("orange")
star.fillcolor('orange')
star.begin_fill()
for i in range(5):
  star.forward(200)
  star.right(144)
star.end_fill()
star.hideturtle()
star.clear()


#thinner longer star
star.pencolor("orange")
#star.fillcolor('orange')
#star.begin_fill()
for i in range(15):
  star.forward(200)
  star.right(168)
#star.end_fill()
star.hideturtle()


#more points
star.pencolor("orange")

for i in range(20):
  star.forward(200)
  star.right(171)
The problem is going to be with the math/principles. There is nothing wrong with the for loop.
I agree, I used the same calculations for all 3 stars, and 2 work and one does not. It's very frustrating.
If you want help with the calculation you should share what you think is the correct calculation.

I don't think you can draw stars with an even number of points (beyond 4) without lifting the pen.