forked from HarshSharmaIN/Python-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolygon.py
33 lines (27 loc) · 768 Bytes
/
polygon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
A turtle graphics python 3 program .
Author: Sajith Minrutha
"""
from turtle import setup, speed, pencolor, penup, pendown, left, forward, exitonclick ,textinput , numinput
# Assign canvas and shape size
canvas_size = numinput("canvas size","Enter the canvas size:")
sides = numinput("sides","Enter the number of sides:")
side_length = 2 / sides * canvas_size
turn_angle= 360/sides
color = textinput("colour","Enter the colour of your polygon:")
# Set the window size and turtle speed
setup(canvas_size, canvas_size)
speed(1)
# Move turtle into position
penup()
left(90)
forward(canvas_size / 3)
left(150)
# Draw a blue polygon
pencolor(color)
pendown()
for side in range(int(sides)):
forward(side_length)
left(turn_angle)
# Finished!
exitonclick()