CS 351: Assignment #3

Graphics Primitives

Due midnight 29 September 2011

In this assignment you will start building your graphics system in earnest. You'll implement several different graphics primitives, including lines, circles, ellipses, and basic polygons. It is strongly recommended that you work with a partner for the rest of the semester and split the work between you.


Graphics Primitives

There are five graphics primitives you will implement this week: Point, Line, Circle, Ellipse, and Polyline. The specific functions and data types are outlined in the C system specifications. If your code follows the specification, you will be able to compile and run the test programs.

Lines: Implement Bresenham's line-drawing algorithm as the basis for the Line_draw() function. Use the version corrected for screen coordinates in the lower left of the pixel.

Calculate how many lines per second your algorithm can draw using this test program. Report your results for running it on one of the computer lab minis.

Circles and Ellipses: Implement the midpoint circle and ellipse algorithms (only standard orientation is required for ellipses) as the basis for the draw functions for these types.

For both the line and circle/ellipse algorithms, make sure to modify the algorithms to take into account the screen coordinate issues as outlined in the class and lab notes.

Here are example circle and ellipse algorithms drawn in the 1st quadrant. You are free to use these as templates for your own routines so long as you acknowledge this in comments within your code. They are from an older web site connected with the Hearn and Baker textbook. Note, however, that you will have to modify their code--put it in the 3rd quadrant--in order to make it correctly handle screen coordinate issues. Note also the order in which their setpixel routine takes its arguments.

Required Pictures

  1. Use the following test program to create required picture #1. If you followed the design specifications, then you will not need to change the source file in order to create the picture.

    Test image A result

  2. Use the following test program to create required picture #2. Note that the function subdivide does need to access the values of the line endpoints. So if your structure fields are named differently, you'll need to edit the test program so it accesses the values correctly.

    Test image B result

  3. Here is a polyline test function. Note the difference in the two green boxes on the lower half of the image. The left one is drawn counter-clockwise. The right one is drawn clockwise.

    Test image C result

  4. Do your best to create a 3-D looking picture of a car, train, plane, or spaceship using these routines (line/polyline, circle, ellipse). Be creative.

Extensions

  1. Giving your routines the ability to draw dashed lines and/or circles & ellipses (easy)
  2. Anti-aliasing your line-drawing and circle drawing routines (moderate)
  3. Creating a flood-fill algorithm so that you can fill in polygons and circles (moderate )
  4. Allowing the user to specify arbitrary orientations for the ellipse algorithm (difficult)
  5. Building a faster line algorithm using symmetry and multiple steps (challenging).

Writeup

Make a child wiki page from your main CS 351 wiki page. Give it the label cs351f11project3. Please follow the format below.

  1. Abstract: 200 word description (at most) of what you did and a picture to go along with it.
  2. Description of the task, in your own words. Be brief, but write it as though explaining it to a fellow student not in the course.
  3. Description of how you solved the task, including any key equations or algorithms. You should also include algorithms or descriptions of what you did for any extensions. Include pictures here.
  4. More pictures. Please put a caption on each picture explaining something about it. If you have nothing else, give it a name and indicate whose picture it is.
  5. Summary of what you learned.

Handin

Put your code files in your private handin folder as a single zip or tar file. Put your writeup on the wiki. Give it the label cs351f11project3.