Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Regular Polygons with Turtle Graphics Python Regular Polygons with Turtle Graphics Create a Python program that will draw, using Turtle graphics, a regular polygon, one

Regular Polygons with Turtle Graphics Python

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 user.

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 0-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://docs.python.org/3.3/library/turtle.html?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 clear(), pencolor(), fillcolor(), shape(), pen_size(), begin_fill(), end_fill(), or ones that do similar things.

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 fill.image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

5. Discuss the key components of behavior modeling training.

Answered: 1 week ago

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago