You are on page 1of 5

CSE 231

Computer Project #6

Fall 2014

Assignment Overview
This assignment focuses on the design, implementation and testing of a Python library module
which uses programmer-defined function and turtle graphics to draw representations of
Scandinavian flags, as described below.
It is worth 40 points (4% of course grade) and must be completed no later than 11:59 PM on
Monday, October 20.
Assignment Deliverables
The deliverable for this assignment is the following file:
proj06lib.py – the source code for your Python library module
Be sure to use the specified file name and to submit it for grading via the handin system before
the project deadline.
Assignment Background
The national flags of six Scandinavian countries are all variations on a similar pattern:

(Source: http://cominganarchy.com/wordpress/wp-content/uploads/2010/07/nordic-flags1.jpg)
You will develop a Python library module that allows the user to draw the flags of these six
Scandinavian countries using turtle graphics.

draw_rectangle. based on the width (see the information about proportions below). Finland. the turtle will be positioned exactly as it was when the function was called (same location and heading). Width of rectangle (floating point) c. 80. It has three parameters: a.0. the following is a valid invocation of the function: draw_flag( "Sweden". 2. 3. The length of the flag will be calculated. The function will display an error message and return (without drawing the flag) if any of the three parameter values are invalid. where appropriate. Color of rectangle (string) For example. Width of flag (floating point) c. Any mix of upper and lower case letters may be used to specify the name of the country (for example. Your library module will consist of three functions: draw_flag. Any mix of upper and lower case letters may be used. and draw_cross (details below). "#FCD116" ) The function will assume the parameters are valid. Name of country (string) b. the following is a valid invocation of the function: draw_rectangle( 120. Iceland. Function draw_flag draws a flag of a certain size and orientation. You may develop additional functions. Norway. It has three parameters: a.0. Function draw_rectangle draws a rectangle and fills it with a color.0. Orientation of flag (string) For example. When the function returns. The upper left-hand corner of the flag (as viewed in landscape mode) will be drawn at the turtle’s current position. and Faroe Islands. 80. The width of the flag (the side parallel to the flag pole) must be greater than zero. DENMARK and denMArk). . Length of rectangle (floating point) b. The function will draw the flag of the specified country. The orientation of the flag must be portrait (long side of flag vertical) or landscape (long side of flag horizontal). Sweden. "landscape" ) Valid country names include Denmark.Assignment Specifications 1.

The turtle is assumed to be in the upper left-hand corner of the rectangle. The turtle is assumed to be in the upper left-hand corner of the rectangle. 6.0. Length of rectangle in which cross will be drawn (floating point) Width of rectangle in which cross will be drawn (floating point) Color of cross (string) Style of cross (string) For example. heading along its length. b. 4. c. For a double cross (such as in the Norwegian flag). d. the function will be called twice. Function draw_cross draws a cross and fills it with a color. The function draws a cross within the rectangle of the specified length and width. For a single cross (such as in the Danish flag). the turtle will be positioned exactly as it was when the function was called (same location and heading). 5.The function draws a rectangle of size length and width. the following is a valid invocation of the function: draw_cross( 120. 80. the turtle will be positioned exactly as it was when the function was called (same location and heading). It has four parameters: a. . The proportions of a flag (ratio of length to width) should be similar to the official proportions of that country’s flag. Important: global variables are not allowed. "#002664". "thick" ) The function will assume the parameters are valid. The colors of a flag should be similar to the official colors of that country’s flag. the fourth parameter will be singleton. 7. any variable names used within a function must be parameters to that function or must be created within that function (appear on the left-hand side of an assignment operation). with thick and thin as the fourth parameters. That is.0. When the function returns. heading along its length. When the function returns.

4. For example. 3. or you can use the official colors (which can be found using Wikipedia). However.org/wiki/Flag_of_Denmark Your flags should look similar to these but need not be exact.py. Be sure to use turtle. 2. The proportions of the six flags are similar and there are only two basic styles. a simple Python program which uses the library module might be: import proj06lib proj06lib.py (and no other Python code will be in that file). 200. Those strings are actually three hexadecimal (base 16) numbers representing the RGB color specification. draw_rectangle. and draw_cross. Here are the specifications of the Norwegian and Danish flags from their Wikipedia pages: http://en.draw_flag( "Norway". You may use simple colors (such as "red"). it must be imported. Your library module (functions draw_flag. If you use official colors.wikipedia.test. . as well as any “helper” functions you create) will be in the file named proj06lib. To use your library module. A longer test program is available in the file named project06. "landscape" ) 5.Assignment Notes 1. a color will be specified using a string such as "#ED2939" (the official Norwegian red). the cross must be centered along the height of the flag and to the left of vertical.wikipedia.colormode(255)at the beginning of function draw_flag.org/wiki/Flag_of_norway http://en.

Test your draw_flag function to draw each of the six Scandinavian flags. Then. 5. 4. Start by developing function draw_rectangle.Suggested Procedure: 1. Draw a flag with one singleton cross such as the Danish flag: call draw_rectangle and then call draw_cross to draw a cross on top of the rectangle. Finally. develop function draw_cross. 3. handle portrait and landscape (which could be handled by simply starting the drawing with the turtle rotated 90 degrees). 2. Draw a flag with two crosses such as the Norwegian flag by drawing a rectangle followed by a thick cross and then a thin cross on top of the rectangle. Example Output: . Draw a plain flag with no cross (simply call draw_rectangle).