For this program you will be using Turtle Graphics to display a graphical representation of your modern art painting “throws”. Here’s a visual of what this could look like:
Turtle Graphics rendering of 10,000 throws
Turtle Graphics rendering of 50,000 throws
Turtle Graphics rendering of 500,000 throws
Input assumptions:
- Number of throws: a value of data type ‘integer’ within the range -2147483648 to 2147483647
- Turtle graphics mode: any string of length 0 to length ~infinity
Here are some hints on how to get started:
- Begin by asking the user if they want to draw the result of the program. This input should be validated and should be case insensitive (i.e. “YES”, “yes” and any other case variation of the word “yes” should both turn on Turtle Graphics mode.
- First, set up a canvas that will be big enough to represent your throws. For example, the size of the painting board is 800px by 500px – perhaps you could set up a canvas that mirrored those proportions
- Next, put Turtle Graphics in “memory” mode – this allows you to draw to the turtle graphics canvas without seeing your drawing unfold in “real time”. To do this simply call this function at the top of your program:
turtle.tracer(0)
- At the end of your program (when you are ready to draw the canvas) you can call this function to cause Turtle to draw all values from memory to the graphical window:
turtle.update()
- When you compute a new throw you should set a distinct pen color for each category
- To draw a point simply move the turtle to that point and draw a short line (for example, you could move the turtle 5 pixels above and to the right of the point and them move 5 pixels to the left and below the point to simulate a line)
- Remember that the Turtle Graphics canvas is oriented using a standard Cartesian coordinate plane. The modern art canvas, however, is not oriented in this way (the origin is at the top left side of the screen). You will have to adjust your display coordinate system accordingly.
- IMPORTANT: For performance & testing purposes you should attempt to write this program so that you are only rendering a few thousand points at any one time (a good debugging number would be 3000 throws)
- Your program should give the user the option of whether they want to display their results in Turtle graphics. Validate this input. For example:
Number of throws: 5000Would you like to draw your results with turtle graphics? (yes/no): pikachuInvalid, try again!Would you like to draw your results with turtle graphics? (yes/no): appleInvalid, try again!Would you like to draw your results with turtle graphics? (yes/no): YeSTotal time elapsed: 0.40 secondsRed: 493 (9.86%)Blue: 224 (4.48%)Grey: 28 (0.56%)Black: 428 (8.56%)Yellow: 62 (1.24%)Green: 530 (10.60%)Misses: 3,235 (64.70%)