Matt Fowles's Graphics Lab 2


This lab focus on drawing various graphics primitives. The first cut at Bresenham's algorithms was pretty simple, since I was allowed to steal the code from Hearn & Baker web-site. Although getting the equations to be mathematically correct (even with Prof. Maxwell's pointers) turned out to be slightly more treacherous. But in the end, all things are doable.


Who did you work with on this assignment, and what tasks did each of you do?

Mu


Describe the API for your graphics environment. This should be a mini-manual on how to use your graphics system. Include the following information in your answer:

PPMwrap mImage;
Point mMaxCoord;
Color mCurColor;

Although the image itself can be accessed directly, this is discouraged but left open just in case I don't think of something that needs to be done (it is also useful for the GUI part of the show...) The max coordinate is currently unaccessible to the outside world, but I could easily change that. Once the environment is constructed the max coordinate is set in stone. The current color variable is only used internally so that lines don't have to pass their color to every pixel. Most of the private functions that do not do bounds checking use the current color, whereas the public functions which do bounds checking are passed the color they should use.

The drawing routines access these state variables directly, extracting whatever information they want from them. There exist private functions to do some of the drawing of primitives that do not need bounds checking (like lines and points). Since these are private, it can be assumed that the methods calling them will check for boundaries ahead of time. Circles and ellipses do not use these directly, since determining whether part of an ellipse is on screen would be difficult.


Is your first required image consistent with how you would match screen coordinates to the true mathematical lines? Why, why not?

lines_required.png My first image is not consistent in that I have not changed the origin from the graphic native upper-left corner. Thus things appear upside-down and backwards from standard mathematical coordinates. Obviously, my lines cannot be perfect given the necessity of pixelation at some level; however, I did implement some things to try and correct simple coordinate issues.

Lines do draw their start point but not their end point (as pixel center coordinate systems would).

Lines in the second quadrant (mathematically) start to the left of their start pixel (so that the line won't appear above and to the right of its proper line).

Vertival and horizontal lines are shifted in a counter-clockwise fashion to allow for correct squares.

All endpoints are switched so that the line will be in one of the first four octants. This does not help mathematical correctness, but it does reduce the number of cases that have to be accounted for.


If you extended this assignment in any way, describe what you did and how you did it. Include pictures to support your description.

I implemented a 4-connected flood-fill algorithm to fill in any area given a point. I also provided for ellipses and circles to be filled in as they were being generated with different fill and edge colors. The flood fill simply uses a stack and expands out from its current point
Ellipses and circles without any filling.
ellipses.png
The inner circle is filled as it is being created; the ellipse
ring is flood filled, after the ellipses are drawn.
ellipses_fill.png



Other stuff?

Well, I made a very nice car with chrome hub caps, although it looks more like a low rider with dilapidated wheels.
car.png
lines_speed.png Oh, right the speed test for lines, almost forgot about that. On a couple of sample runs I got:
168675
181155
178369
186818
My system is a win2k machine with 256 MB ram and a 700 mhz processor. I did have a few heavily load apps open at the time (VC++, IE, and Outlook)

I have been maintaining my GUI, too... Although I have not yet added the fill options for it.

Last modified 2003-10-07 22:15 EST