CS1112 Spring 2014 Project 3 Part A due Thursday 3/6 at 11pm (Part B will appear in a separate document. Both parts have the same submission deadline.)

You must work either on your own or with one partner. If you work with a partner you must first register as a group in CMS and then submit your work as a group. Adhere to the Code of Academic Integrity. For a group, “you” below refers to “your group.” You may discuss background issues and general strategies with others, but the work that you submit must be your own. In particular, you may discuss general ideas with others but you may not work out the detailed solutions with others. It is not OK for you to see or hear another student’s code and it is certainly not OK to copy code from another person or from published/Internet sources. If you feel that you cannot complete the assignment on you own, seek help from the course staff.

Objectives

Completing this project will solidify your understanding of user-defined functions and vectors. Part 1 focuses on user-defined functions and graphics; Part 2 additionally involves vectors.

1 The of Look up the flag of Uzbekistan. You will probably find some images as well as the philosophy of the flag (the meaning of the colors, crescent, and stars), but the actual positions and sizes of the stars and crescent are not specified. (Or at least I cannot find the specification in English.) You will make several visualizations of the flag by rotating the stars. However, the sizes and positions of the elements of the flag should be similar to the typical images of the flag that you see, an example of which is shown on the right. Using one figure window, you will show four visualizations of the Uzbek flag, one in each quadrant: Top left All the stars have a point due north (as shown in the image above).

Top right Each in the top row has a point due north; each star in the middle row has a point due east; each star in the bottom row has a point due south. 2π Bottom left For k = 1, 2,..., 12, the kth star has a point at k 12 radians. It’s up to you how to number the stars, but the 12 angles must be represented. Bottom right Make your own design regarding the rotation of the stars, but this visualization must be different from the previous three.

Specifics and hints 1. Start by reading Insight §5.3 (The Betsy Ross flag) first—it’ll help you with this problem! 2. Download the m-files DrawRect.m and DrawStar.m from the Insights page of the course website and DrawDisk.m from the Lecture Materials page. Study them to make sure that you know how they work. These functions draw the specified shape with a black outline. In order to draw the flag of Uzbekistan, you need to modify these functions to draw the colored shapes without a black outline. This can be done simply by modifying the last statement in each file, which calls the built-in function fill, to be fill(x,y,c,’line’,’none’)

Do this for DrawRect and DrawDisk and change the function names (and therefore filenames) to be DrawRectNoBorder and DrawDiskNoBorder. You will deal with DrawStar separately later. 3. By making effective use of DrawRectNoBorder and DrawDiskNoBorder, implement the following function as specified:

1 function DrawBackground(a,b,h) % Add all elements of the Uzbek flag except the stars to the current window. % The lower left corner of the flag is at (a,b). % The flag has height h and width 2h. % Assume hold is on.

The dimensions of the flag elements should be expressed in terms of the parameters. For instance, do not hard code the height of the bar of the flag to be some fixed literal value; instead, set the height in terms of h, e.g., something like h/3 or smaller.

A note on color: We have been using Matlab’s prespecified color names, e.g., ’r’ for . Instead of using a color name, we can specify the exact color vector, e.g., DrawDisk(0,0,1,[1 0 0]) will draw a red disk because the “rgb vector” [1 0 0] specifies red (full contribution of red, zero and blue). Take a look at this webpage that shows color swatches and their corresponding rgb val- ues: http://prideout.net/archive/colors.php The last column of the table shows the values that should go into the rgb vector. Pick colors that are reasonably close to those of the Uzbek flag. 4. Modify DrawStar and save it as the function DrawRotatedStar. The original DrawStar draws a 5-pointed star that has one star tip due North and has this specification: function DrawStar(xc,yc,r,c) % Adds a 5-pointed star to the current window. % Assumes hold is on. % The star has radius r, center (xc,yc) and color c where c is either an rgb vector % or one of the built-in colors ’r’, ’g’, ’y’, ’b’, ’w’, ’k’, ’c’, or ’m’.

Your function DrawRotatedStar should have a fifth parameter for the “clock point” expressed in radi- ans. Be sure to (re)write the function header and comments to match your function. For example, the command DrawRotatedStar(0,0,1,’y’,pi/2) should draw the same star produced by the command DrawStar(0,0,1,’y’).[Hint: All you need to do is to change the coordinates of the vertices by rotation. Think angle.] Finally, revise the function call to fill to exclude the black outline. 5. Write a function FlagDesigns to draw the four visualizations of the flags in one figure window, as described above. This function sets up the figure window and draws the flags by calling your func- tions DrawBackground and DrawRotatedStar, as well as any subfunctions that you may wish to define. FlagDesigns has no input parameters, so the function header should be function FlagDesigns()

Normally, a function with no parameters could have been written as a script instead. However, we want to allow you to specify subfunctions if you wish. Therefore FlagDesigns.m needs to be a function file and not a script. (Only a function file can contain subfunctions; a script cannot contain subfunctions.)

Submit your files DrawBackground.m, DrawRotatedStar.m and FlagDesigns.m only. We will use our ver- sions of DrawRectNoBorder and DrawDiskNoBorder when we test your code.

Part B of Project 3 will appear in a separate document.

2