Objectives
Design an
algorithm
(a set of steps for solving a particular problem).
Be able to define and call a
function
Use iterative, incremental
development and composition when writing an application.
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;
mso-font-charset:2;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:0 268435456 0 0 -2147483648 0;}@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;
mso-font-charset:0;
mso-generic-font-family:roman;
mso-font-pitch:variable;
mso-font-signature:3 0 0 0 1 0;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin:0cm;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman",serif;
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:EN-US;
mso-fareast-language:EN-US;}.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
font-size:10.0pt;
mso-ansi-font-size:10.0pt;
mso-bidi-font-size:10.0pt;
mso-ansi-language:EN-US;
mso-fareast-language:EN-US;}div.WordSection1
{page:WordSection1;}ol
{margin-bottom:0cm;}ul
{margin-bottom:0cm;}
Part 1 - A fancy turtle boxtrot — In Part 1, you will write the functions to draw a figure that will look the figure below. The only difference is it will display your initials instead of WG. The steps to do this our detailed below. 1. Import the turtle module. 2. Write a function called draw_filled_square. It will take three (3) parameters: a turtle, the size of the square, and a color. The function header will look like the following: def draw_filled_square(turtle, size, color): 3. Inthe draw_filled_square function body do the following: a. Invoke the turtle’s fillcolor function, to set the fill color to the color that was passed to the function. b. Turn the fill on for the turtle using the turtle’s begin_fill function. c. Draw a square of the size specified via the Size parameter using a for loop. d. Turn the fill off using the turtle’s end_fill function. 4. Write a function called draw_picture that will not take any parameters. In this function do the following: a. Create the screen. b. Create the turtle. c. Draw the four boxes alternating the blue and green colors as depicted above. Remember to call the draw_filled_square you wrote in Steps 2 and 3 above. i. The boxes should be of size 300 and centered at (0, 0). 5. Save and run the program to verify the four boxes are drawn. Do not move on until they are drawn correctly. 6. Refactor the code and move the code that draws the four boxes into a function called perform_ boxtrot. This function will need to take one parameter which is a turtle. The function header will be: def perform_boxtrotturtle): a. When you move this code, make sure you replace the name of the turtle with the name of the turtle parameter. 7. In the draw_picture function add a call to perform_boxtrot and pass it the turtle that was created in the draw_picture function. 8. Save and run the program to verify the four boxes are still drawn. Do not move on until they are drawn correctly. Part 1 — Drawing initials Next, you will write the code to draw your first and last initial, ¢.g., if your name is Bob White, you will write code to draw a B and W. 1. In the draw_picture function, after the call to perform_boxtrot add a call to a function named draw_first_initial and pass it the name of the turtle that was created in the draw_picture function. 2. Add a new function called draw_first_initial that takes one parameter which is a turtle. The function header will be: def draw_first_initial(turtle): 3. Inthe draw_first initial function body, add code to draw your first initial in the upper-left corner box. 4. Save and run the program to verify the four boxes are still drawn and it draws your first initial in the upper-left box. 5. Inthe draw_picture function, after the call to draw_first_initial add a call to a function named draw_last_initial and pass it the name of the turtle that was created in the draw_picture function. 6. Add a new function called draw_last _initial that takes one parameter which is a turtle. The function header will be: def draw_last_initial(turtle): 7. Inthe draw_last initial function body, add code to draw your last initial in the lower-right corner box. 8. Save and run the program to verify the four boxes are still drawn and it draws your first and last initial in the correct locations. 9. This completes the requirements for Part 1 of the project, so add a comment at the top of the file that states you: Successfully completed Part 1 of the project. If you didn’t complete all of Part 1, then in the comment state what you did complete. 10. 1 would encourage you to upload what you have completed to CourseDen. I would also suggest keeping a backup of this file. 11. If you successfully completed all of Part 1 and you so desire, you may proceed onto Part 2 of the project. Part 2 - A matte, a frame of triangles, and a second turtle (14 pts.) Part 2 will not be as detailed as the step-by-step specifications for Part 1 were. The requirements will be given and you will need to figure out how to implement them. In Part 2, you will create a second turtle whose responsibility is to draw a matte and border of made out of triangles. An example of the resulting figure is depicted below: 1. In the draw_picture function create a second turtle object. 2. Use the second turtle object to draw the gray matte around the initialed box trot. a. Hint: Think about drawing the matte first. 3. Ifneed be, refactor the code and extract this gray matte drawing out to its own function and call that function within the draw._picture method. 4. Add functionality to create the triangle frame border depicted above. This border must be drawn using the second turtle you created. a. Make sure your code adheres to the Single Responsibility (SRP) and Don’t Repeat Yourself (DRY) principles. 5 . This completes the requirements for Part 2 of the project, so add a comment at the top of the file that states you: Also, successfully completed Part 2 of the project. If you didn’t complete all of Part 2, then in the comment state what you did complete. 13. 1 would encourage you to upload what you have completed to CourseDen. I would also suggest keeping a backup of this file. 14. If you successfully completed all of Part 2 and you so desire, you may proceed onto Part 3 of the project.