Answered step by step
Verified Expert Solution
Question
1 Approved Answer
*This question was already answered but the answer was handwritten and illegible* Regular Polygons with Turtle Graphics Create a Python program that will draw, using
*This question was already answered but the answer was handwritten and illegible*
Regular Polygons with Turtle Graphics Create a Python program that will draw, using Turtle graphics, a regular polygon, one with each side the same length and each angle of the same size, with the number of sides greater than 2 as chosen by the Your code should prompt the user to enter the number of sides he/she would like to see. Use a while loop to allow the user to draw as many polygons as desired. Use the number of sides being less than 3 as the indicator that the user does not want to draw any more polygons. Use a for loop to draw the polygon with side length of (600umber of sides) pixels, that gives us a polygon of circumference of 600 pixels, and a color from the colors list as specified below. The angle, in degrees, to turn right or left may be calculated as 360 divided by the number of sides. For example, the angle for a 12 sided polygon is 360/12-30. The angle for a six sided polygon is 60 degrees. The polygons will be drawn with a border color, a fill color, and a border width. Before each new polygon is drawn, the turtle graphic area should be cleared. Set the shape of the turtle to look like a turtle. The colors list should be defined as follows: # Specify the colors list to choose the line color and fill color. colors ['coral, gold, brown, 'red, 'green, blue, yellow, purple, 'orange, 'cyan, pink, 'magenta, 'goldenrod] To select a color from the colors list, generate a random integer in the range 0-12 and use that as the index into the colors list To make sure that the border does not get too fat, we will set its size to be sides%20 + 1. The modulus operator % will give us a value of O-19, that will give us a width of 1.20 To draw the polygon, you will write a function with the following header definition: # The makePolygon function draws a polygon with the number of sides. # side length, border color, border width, and fill color as specified. def makePolygon (sides, length, borderColor, width, fillColor) where sides is the number of sides of the polygon, length is the length of each side, borderColor is the color of the border of the polygon, width is the width of the border, and fillColor is color the polygon is filled with. This function will be called from the main part of your program to draw the polygons. Full documentation about all the functions that can be used with turtle can be found at: https: d vt r highlight-turtle There are several functions to do the same thing in turtle, you may pick any one that works. Your program will need to use turtle functions such as clear0. pencolor), fillcolor0, shape). pensize), beginfil. end f), shape0 or ones that do similar things. Sample execution: Fython 3.64 3.6.4d4leceb, Dec 19 2023 06:04:45 ype eopyrightcedita" or1ineD-for ore in START:P:/pac131/Programing Aasigneent 8olutio nter tho nusber of aidos, 1 than 3 to extt: tee tha ube of sides,1ess Uhan 3 to it: manks toE using poygon gen ATOE PEOg Your polygon will not necessarily have the same colors since they are randomly selected. Notice the turtle in the drawing, its' back is the color of the fillStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started