CS 351: Assignment #3

Graphics Primitives

Due 25 September, 2014

In this assignment you will start building your graphics system in earnest. You'll implement several different graphics primitives, including lines, circles, ellipses, and polylines. You can work in pairs, starting with this assignment.


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 robot lab dwarves.

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. You can find the instructions for that in my lecture notes. Note 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 test program for the polyline functions. 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, or anything else of your choice, using these routines (line/polyline, circle, ellipse). Be creative. If you are working with a partner, each of you must make your own image for this task.

Extensions

  1. Give your routines the ability to draw dashed lines and/or circles & ellipses.
  2. Anti-alias your line-drawing and circle drawing routines.
  3. Create a flood-fill algorithm so that you can fill in polygons and circles.
  4. Allow the user to specify arbitrary orientations for the ellipse algorithm.
  5. Build a faster line algorithm using symmetry and multiple steps or just through better coding.

Writeup

Make a child wiki page from your main CS 351 wiki page. Give it the label cs351f14project3. Put up your required and portfolio images along with brief descriptions and relevant information. If you are working with a partner, make only one wiki page, but you must each make your own images when there is creativity involved. You must also each make your own portfolio images.

Handin

Put your code in a zip file in your Private handin folder. Put your writeupon the wiki. Give it the label cs351f14project3.