Question: Write a Python program to draw a sequence of filled polygons of possibly different colors. The program reads in the corners (vertices) of the polygons

 Write a Python program to draw a sequence of filled polygonsWrite a Python program to draw a sequence of filled polygons of possibly different colors. The program reads in the corners (vertices) of the polygons as a sequence of integers separated by commas, from the keyboard. Each corner is specified by a pair of x and y coordinates. The colors are maintained in a list. In this implementation, store just three colors: red, green, and blue. Cycle through these colors for the successive polygons. The first polygon is colored red, the second is colored green, the third is colored blue, the fourth is colored red, and so on. The program ends when the user presses the Enter key without typing any other characters. The program asks for the coordinates as a sequence of integers. The interaction should be as below.
Enter all x and y coordinates separated by commas 0, 40, 50, 50, 80, 0
Enter all x and y coordinates separated by commas 100, 80, 120, 100, 140, 60, 100, 40
Enter all x and y coordinates separated by commas -30, -40, -70, -20, -100, -90, - 120, -40, -30, 0
Enter all x and y coordinates separated by commas -30, 40, -70, 20, -10, 0
Enter all x and y coordinates separated by commas
The program should be structured such that it has three functions with parameters and functionalities as indicated:
1) get_corner(coordinates): The parameter coordinates is a list of an even number of integers. The function extracts from coordinates the first two integers and returns this pair as a list of two integers: the x and y coordinates of a corner of the polygon. The function also deletes from coordinates the first two entries, which were returned by it.
2) draw_polygon(corners, polygon_color): Draws a polygon whose corners are available as a list in the parameter corners. The polygon is filled with the color given in the second parameter color. The function calls get_corner() repeatedly to extract successive corners.
3) main(): Creates the list of colors. It then prompts for and reads lines of integers until a line with no characters in it is read. You may assume that each non-empty line has an even number of integers with each pair separated by a comma. The function then creates a list out of these integers and calls draw_polygon().

l MetroPCS LTE 15:42 a m etrostate.learn.minnstate.edu 2 of 3 The functionalities as indicated: program should be structured such that it has three functions with parameters and 1) get ): The parameter coordinates is a list of an even number of integers. The function extracts from coordinates the first two integers and returns this pair as a list of two integers: the x and y coordinates of a corner of the polygon. The function also deletes from coordinates the first two entries, which were returned by it. 2) draw polygon(corners, polygon_color): Draws a polygon whose corners are available as a list in the parameter corners. The polygon is filled with the color given in the second parameter color. The function calls get comer) repeatedly to extract successive corners 3) main(k Creates the list of colors. It then prompts for and reads lines of integers until a line with no characters in it is read. You may assume that each non-empty line has an even number of integers with each pair separated by a comma. The function then creates a list out of these integers and calls draw polygon( Submission Submit the Python file to the dropbox for Assignment 10. Remember the hard deadine Grading Criteria for the Program 1. The code begins with the student's name as a comment (1 point) 2. Meaningful comments (input, functionality, and output) appear before the first executable 3. Correctness of output (8 points) 4. The three functions are defined, implemented, called correctly, and fully made use of Ifa function is meant to do something, it should do it, and the caller should not resort to

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!