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.

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

The function draws a rectangle of size length and width. The turtle is assumed to be in the upper
left-hand corner of the rectangle, heading along its length.
When the function returns, the turtle will be positioned exactly as it was when the function was
called (same location and heading).
4. Function draw_cross draws a cross and fills it with a color. It has four parameters:
a.
b.
c.
d.

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, the following is a valid invocation of the function:


draw_cross( 120.0, 80.0, "#002664", "thick" )
The function will assume the parameters are valid.
The function draws a cross within the rectangle of the specified length and width. The turtle is
assumed to be in the upper left-hand corner of the rectangle, heading along its length.
For a single cross (such as in the Danish flag), the fourth parameter will be singleton. For a
double cross (such as in the Norwegian flag), the function will be called twice, with thick and
thin as the fourth parameters.
When the function returns, the turtle will be positioned exactly as it was when the function was
called (same location and heading).
5. The proportions of a flag (ratio of length to width) should be similar to the official
proportions of that countrys flag.
6. The colors of a flag should be similar to the official colors of that countrys flag.
7. Important: global variables are not allowed. That is, 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).

Assignment Notes
1. The proportions of the six flags are similar and there are only two basic styles. Here are the
specifications of the Norwegian and Danish flags from their Wikipedia pages:
http://en.wikipedia.org/wiki/Flag_of_norway http://en.wikipedia.org/wiki/Flag_of_Denmark

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

Suggested Procedure:
1. Start by developing function draw_rectangle. Draw a plain flag with no cross (simply
call draw_rectangle).
2. Then, develop function draw_cross. 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.
3. 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.
4. Test your draw_flag function to draw each of the six Scandinavian flags.
5. Finally, handle portrait and landscape (which could be handled by simply starting the
drawing with the turtle rotated 90 degrees).
Example Output:

You might also like