Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
turtle calculate angles
#1
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)
Reply
#2
The problem is going to be with the math/principles. There is nothing wrong with the for loop.
Reply
#3
I agree, I used the same calculations for all 3 stars, and 2 work and one does not. It's very frustrating.
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  wn = turtle.screen() AttributeError: module 'turtle' has no attribute 'screen' Shadower 1 6,171 Feb-06-2019, 01:25 AM
Last Post: woooee
  Turning Robot towards goal, comparison of angles SpaceTime 0 2,749 Jan-21-2019, 10:26 PM
Last Post: SpaceTime
  Help! Turtle not working, even when we click the turtle demo in IDLE nothing happens. BertyBee 3 5,619 Jan-04-2019, 02:44 AM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020