Drawing polygons in python turtle

G

geniusrko

Hi
can anyone help finding the angle to draw different polygons shapes

in this example

import turtle
wm = turtle.Screen()
alex = turtle.Turtle()
for i in range(5):
alex.left(216)
alex.forward(50)
wm.exitonclick()

Why do we use 216
 
D

Dave Angel

Hi
can anyone help finding the angle to draw different polygons shapes

in this example

import turtle
wm = turtle.Screen()
alex = turtle.Turtle()
for i in range(5):
alex.left(216)
alex.forward(50)
wm.exitonclick()

Why do we use 216

216 degrees doesn't seem to me that it would make a polygon, but
rather a star.

I can tell you what I remember about geometry, however. To make a
regular polygon, you need to turn by a fixed amount and go a
fixed distance each time.

For an equilateral triangle, you turn 120 degrees. For a square,
90. For a pentagon, 108.

180 - (360/n) degrees.
 
A

Asaf Las

Hi

can anyone help finding the angle to draw different polygons shapes
in this example
import turtle
wm = turtle.Screen()
alex = turtle.Turtle()
for i in range(5):
alex.left(216)
alex.forward(50)
wm.exitonclick()
Why do we use 216

because of every for every turn we need to make angle between edges
equal to 36. If you will have a look to pentagon definition:
http://en.wikipedia.org/wiki/Pentagon
inner angle is equal to 108. from that you can easily calculate
the angle between edges of star.
there is no difference between these 2:

alex.left(216)
alex.right(144)

change left() to right() and see.

/Asaf
 
A

Asaf Las

because of every for every turn we need to make angle between edges
equal to 36. If you will have a look to pentagon definition:
http://en.wikipedia.org/wiki/Pentagon
inner angle is equal to 108. from that you can easily calculate
the angle between edges of star.
there is no difference between these 2:
alex.left(216)
alex.right(144)

change left() to right() and see.
/Asaf

just a bit add - confusing things here is the reference of 0 degree turtle
takes to make turn from. i was also confused when so that (never tried
turtle before). the 0 degree is the virtual line which is continuation
of direction from point where forward(50) ends. so when left executes
it should turn more than 180 to achieve 36 degrees and when right -
less.

p.s. i am not good in explaining things.
 
A

Asaf Las

Well how about the star of david what are the angles

hexagon is not constructed similar to your program for pentagon
because crossing path can't jump from one triangle to another.
you have 60 degrees turn after 2 turns edges will be concatenated.

/Asaf
 
A

Asaf Las

A better way to draw stuff on screen

It depends on particular case/figure you wish to draw.
Drawing is separate knowledge field with its own set of algorithms.
Geometry is field of wonders.

i never dealt with this stuff actually.
 
A

Asaf Las

Going off-topic Which resource do you recommend for learning this
wonderful language

My advice won't be good as mentioned before i never dealt with it.
You have chance to discover that country yourself or wait for advice of
others or do both at same time.
 
T

Terry Reedy

Is there a better way of drawing such as another modules

Logo is a drawing language designed for kids who do not know geometry
but can imagine walking around on a dirt field and occasionally turning
while dragging a stick or dripping paint. Part of the charm is
discovering the patterns that emerge when simple actions are repeated.

The Python version, turtle, is built on top of tkinter and its Canvas
widget. Since I *do* know coordinate geometry and don't care about the
moving animal metaphor, I find it easier to use Canvas directly. This
avoids the bugs and limitations (including speed) introduced by the
turtle module.
 
D

Dennis Lee Bieber

Well how about the star of david what are the angles

The Star of David is not single polygon... It is two equilateral
triangles overlayed. You can not draw one using a single pen stroke and
fixed turn angle.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top