Retro Graphics

In this lab you will implement a very simple raster graphics system, using a simulated ASCII graphics display. The purpose of this exercise is to get you started in thinking graphically. (And to test that your account works, the system has the right libraries, etc.) It is not the kind of programming that you will be doing for the rest of the semester.

Download either the C or Java versions of the ASCII graphics simulator to your CG directory. Untar the contents with tar -xvf ctty.tar or tar -xvf jtty.tar. This will create a directory cTTY or jTTY respectively. Change into it.

The C version should build by just typing make, the Java version by javac Retro.java. If it doesn't, your machine may not be set up correctly and you need to talk to your tutor.

Run the program with either ./retro or java Retro. You will see a blank screen. Nothing happens when you press the mouse or keys except that you can Exit by either pressing the ESCAPE key or clicking the right mouse button inside the window and choosing the Exit command.

Run your preferred editor on retro.c or Retro.java and skim through the code until until you find the section that responds to keystrokes. (Don't bother trying to understand the rest of it: we will go through this in detail in a later lecture.) You will see that the V key draws a vertical line, the H key draws a horizontal line, and the R keys draws a rectangle. They don't work yet.

The actual code for these operations is in tty.c or TTY.java. Your task for this lab is to implement these operations by writing characters into the "frame buffer". (Not by using Xlib, Java2D, or any other real graphics library.) The Clear operation has been written for you already as an example.

1. Change the Clear code so that it fills the frame buffer with the character 'M' instead of a space. Rerun the program.

2. Implement Fill. Test with the R key.

Make sure you have not swapped horizontal and vertical. The rectangle should be twice as wide as high, not the other way around!

3. In the main program, replace Clear by a Fill of the entire screen with spaces.

4. Implement Line. You only need to do horizontal or vertical lines, and can ignore requests for others. (It's easiest to write two blocks of code, one for horizontal and one for vertical.)

5. Add a keystroke that uses several Line or Fill operations to draw the current year in the blocky line style of a digital watch or calculator LED display.

Optional advanced:

6. Change the requested width and height for the rectangle key to be 100 by 100. Add clipping code to your implementation so that it does not crash.

7. Replace the two dimensional [ROWS][COLS] array used for the TTY buffer by a one dimensional [ROWS * COLS] array with integer math in the implementation to calculate the equivalent elements. You will also need to rewrite the display function in the main program.

8. Before raster graphics, there were only vector displays. Try the vector graphics simulator exercise.