# Machine Problem 4, due Mar 30

Background: Consider the following sequence of 4 figures:

```0   1     2          3
[]  []    [][]       [][][][]
[][]  []         []    []
[]    []   []
[][][][]   [][]
[][]        [][]
[]            []
[]    [][]    []
[][][][][][][][]
```

The numbers above each figure are its order. A figure of order n is 2n characters high and is 2 × 2n characters wide.

For n > 0, each order n figure is made up of 3 order n–1 figures, one rotated +90° and one rotated –90°.

As an alternative to rotation, you can think of each For n > 0, each Order n figure, where n > 0, as being composed of 4 order n–1 figures, where the printing of one of those figures has been suppressed.

The Assignment: Write a well commented SMAL Hawk program to plot the largest order figure that will fit on the screen, centered on the screen. Your solution should be submitted in the usual way, in a source file called mp4.a by the end of the day on the due date.

Notes: There are two separate parts of the assignment: Sizing and centering the figure, on the one hand, and plotting the figure, on the other hand. These can be solved independently. You can write a main program that calls the plot routine at a fixed location with a fixed order and orientation, in order to debug the plotter, and you can, separately, write a main program that finds the center of the screen and computes the right order without plotting.

Obviously, you need the screen dimensions to find the center. Here is the relevant text from Chapter 5 of the notes explaining how you can get this information:

The monitor calls DSPINI to initialize the display software immediately before it calls your main program, leaving the return values from DSPINI as parameters to your main program.

As a result, the parameters to the main program are R3 and R4, the width and height of the drawing area in the Hawk window, measured in units of characters. Divide either of these by two to find an integer approximation of the center of the screen.

It should be fairly obvious that the plot routine will be recursive. The parameters to each call include, at the very least, the order of the figure to be plotted, the coordinates where it should be plotted, and the direction it should face (or which sub-figure should be suppressed).

For the problem of rotation, consider encoding the "angle" of the figure using the integers 0 through 3. To rotate the angle r one step right, (r + 1)mod 4 will work. Note that (r + 3)mod 4 and (r – 1)mod 4 are equivalent. Curiously, as I learned only after I set out to solve this problem, the computation just discussed was never necessary in the final version of my code.

You can set the font size in your terminal window very small and then make the window very big before testing your program if you want to see a high-order figure. Of course, get it working first in a small order.

Submission: As usual, use the on-line (and rather clunky) submit command, selecting the course cs_2630 and the assignment mp4; your source file must be named mp4.a and it must contain a title line formatted (as usual) as:

TITLE "mp4.a by Yourname Here"

Of course, substitute your own name for Yourname Here, since we do not know of any students named Here.

As usual, you must cite your sources. If you find an old assignment on line that you use as a framework, modifying it to solve this problem, give a comment up near the top of your program giving the URL of that code.