CS-141 Winter 2013

Lab 7: Flags from around the world

For this lab (shamelessly stolen from Jaime Spacco), you will use a library called SimpleGrid to draw flags from around the world. You can copy the given code from the course directory on the windows systems: Open the start menu and select Computer, departments, CompSci, CS141. Then copy the FlagLab directory and open this project in BlueJ.

When you create a FlagMaker object, the constructor will ask you which flag to draw and how big. Try entering 1 for the flag number to draw the flag of Indonesia (which is already implemented for you), and try something like 12 for the size. Once you're sure that this works, examine the code to see how it works.

The SimpleGrid class handles all the display. You just need to know how to use it. It supports methods getNumRows and getNumCols to get the grid size and setColor to set the color for a pixel. The third argument to setColor is the desired color; Java knows about Color.RED, Color.YELLOW, Color.GREEN, Color.BLUE, and Color.BLACK (among others).

There are 9 flags for you to work on (courtesy of Fawzi Emad at
the University of Maryland). **You don't
have to finish all of them!** Try to finish the first 5 (Indonesia,
Lithuania, Rwanda, Malta, Afghanistan) and at least 1 of the next 4 (Eritrea,
Macedonia, The Bahamas, Zimbabwe).

**Information and Pictures about the flags:**

** **

This file contains detailed information about each flag required for this lab and pictures of each flag in two different sizes. Realize that these are just examples – two randomly chosen sizes. From the description, you need to be able to extend this to any other valid size for that flag.

**1 Indonesia **

The Indonesian flag is two equally spaced
horizontal stripes where the top is **red**
and the bottom stripe is **white**.

The height specified by the user **must be a multiple of two**. The multiple of two allows the stripes
to be of the same size. If a
Ònon-multiple of 2Ó value is given, your code may not work correctly.

Size 6

Size 18

** **

**2 Lithuania **

The Lithuanian flag is three equally spaced horizontal stripes where top is yellow, the middle green and the bottom red.

The height specified by the user **must be a multiple of three**. The multiple of three allows the three
stripes to be of the same size. If
a Ònon-multiple of 3Ó value is given, your code may not work correctly (that's
OK).

Size 6

Size 12

**3 Rwanda **

The flag for Rwanda is three horizontal stripes (we are going to skip the sun). The horizontal stripes are not equal. The top, the blue stripe, is the top half of the flag, and the bottom half is two equally sized horizontal stripes which are yellow and green.

The height specified by the user **must be a multiple of four**. If a value is given that is not a
multiple of four, your code may not work correctly (that's OK).

Size 4

Size 12

**4 Malta **

The flag for Malta has two equally spaced vertical stripes (we are going to ignore the top left corner). The left half is white and the right half is red. This flag can be drawn in any size because the width of a flag is always even.

Size 5

Size 10

**5 Afghanistan **

The flag for Afghanistan has three equally
spaced horizontal stripes (**black**, **red** and then **green**). We will skip
the crest in the middle.

The height specified by the user for this
flag must **be a multiple of three**. If a non-multiple of three is given,
then your code may not work.
(Note: the size typed by the user is actually the height, but because
the width is 2 times the height, the width would also then be a multiple of
three.)

** **

Size 9

Size 24

**6 Eritrea **

The flag for Eritrea has three triangles (again skipping the crest). The red triangle covers the whole left side and goes to a single point on the right side. The single point will be a single pixel high when the height of the flag is odd but will be two high when the height of the flag is even. The triangle above the red is green and below is blue. The red triangle must cover the whole left side of the flag and then get one unit smaller on each side after each set of four columns until it comes to a point in the vertical center of the flag. (Note in the pictures shown how the odd and even have different methods of ending in a point - so the last set might not have a whole set of four.) The height specified by the user for this flag can be of any size.

Size 5

Size 20

**7 Macedonia **

The flag for Macedonia has a **red** background with **orange sun** that has a center part
connected to vertical, horizontal and diagonal lines in each direction. The center we are going to make
rectangle for ease in drawing and it will be a 4x8 rectangle regardless of the
size of the flag. The vertical
line will be exactly two pixels wide, and the horizontal line will be exactly
two pixels high. The diagonals
must be two wide with no overlap from segment to segment.

The height specified by the user for this
flag **must be even and at least 8**. If an odd value is given or a value
less than 8 is given, your code may not work.

Size 10

Size 16

**8 The Bahamas **

** **

The flag for The Bahamas has three equally spaced horizontal lines (they might not be exactly equal in this picture, but we will take artistic license on that too). It also has a black triangle that covers the left side completely and gets one smaller on each side until it reaches a point. The color in the center stripe is "gold" but we will use yellow to represent gold.

The height specified by the user for this
flag **must be an odd multiple of three**. It is a multiple of three so that the
stripes can be equally spaced. It
must be odd so that the triangle comes to a single character at the point. If value is given that is not a
multiple of three or it is even, your code may not work correctly.

Size 9

Size 15

**9 Zimbabwe **

The flag for Zimbabwe has 7 equally spaced horizontal stripes and a white triangle. The size of the flag must be a multiple of 7. (We are ignoring the bird and the black outline of the triangle.) The triangle must completely cover the left side, and must come to a single character point when odd or a 2 character high point when even.

The height specified by the user for this
flag **a multiple of 7**. If a non multiple of 7 value is given,
your code may not work correctly.

Size 7

Size 28