BU CLA CS 480: Introduction to Computer Graphics

Spring 1995

Programming Assignment 1---due Friday, February 10


This programming assignment is meant to acquaint you with two basic concepts in interactive graphics programming: scan conversion and area filling. You will write a few subroutines in C, and then link them with some other routines and a main program that are provided. The resulting program will be a simple line sketch tool that can draw lines and do flood filling.

Since the sketch tool program runs on the SGI, you will need to use one of the SGI workstations in the CGL cluster (unless you have access to an SGI workstation elsewhere).

Copy Some Files

Some basic graphics utilities and the sketch tool's main program are provided for you. So, before you begin programming, you will need to copy six files from the directory /usr3/faculty/sclaroff/program1 on the CGL cluster. These files are:

By copying the source files, you have almost everything you'll need to build your own sketch program. You are expected to complete the sketch program by providing two missing subroutines using the code templates. There are comments in the two template files that will help guide you in writing your own subroutines.

Run the Example Sketch Tool

In the same directory, you will also find an example of a fully functioning sketch tool: sketch_example . You may run this to see how your program should work. The user interface to the sketch tool is through mouse buttons and keyboard keys:

The Code You Write

You are expected to write two new routines based on the templates provided in the files line.c and fill.c :

  1. Write a line rendering routine that uses the midpoint algorithm (Program 3.2 in the book). Modify the basic mid-point algorithm algorithm so that it can handle lines at any angle.

  2. Write a flood fill routine based on the algorithm that will be described in class early next week.
Test Cases

There are two test cases provided. To toggle between the test cases, press the T key. You can preview these test cases in the example sketch tool sketch_example . The first test case is a green spoke pattern. This case will help show that your line drawing routine can draw lines at all angles. The second test case is a flower pattern. You should use this test case to test your flood fill algorithm. Your flood fill routine should successfully fill any part of the flower (center or petals). In addition, it should successfully fill the area outside the flower.

Grading

Demo

Part of your grade for this programming assignment will be based on your giving a short demo (2-3 minutes) in the CGL cluster. You will be expected to talk about how your sketch tool works, and we will see how well your program works on some test examples. Two of these test examples are provided so that you can debug your program. Demos will be scheduled for Friday Feb. 10, from 3:00 to 7:00. You will be asked to sign up for a slot by next Friday.

Write-up

You will also be graded on a very brief write-up that is to be turned in at the beginning of class on Friday, Feb. 10. Basically, this write-up should include a paragraph describing what design choices you made in writing the sketch tool, and hard copy of all your code. The code should be commented so that it is easily understood.

Extra Credit

For extra credit, change your flood filling routine to do patterned area fill. Use the fill seed point as the texture's anchor point. To accomplish this, you will need to write a pattern generating function. You may also want to make it so that hitting the F key toggles pattern fill on and off.

Start programming early. Late assignments will not be graded.

Utilities provided

The file draw.c contains utilities for opening and managing windows:

  • open_window opens a window and initializes the device event handling
  • close_window closes a window

    There are also pixmap management routines:

  • create_pixmap allocates and initializes a pixmap data structure
  • free_pixmap frees a pixmap
  • post_pixmap posts the pixmap to the graphics window
  • set_pixmap sets the entire pixmap to a particular color

    There are two macros for reading/writing pixels in the file draw.h :

  • write_pixel writes a pixel to a pixmap
  • read_pixel reads a pixel from the pixmap

    Finally, there are two other important routines:

  • draw_point draws a blue point symbol directly to the window
  • get_event waits to get an event from the event queue


    Stan Sclaroff
    Created: January 17, 1995