Alex Benn and Andrew Frampton
Our objective was to write a graphics library, designed to provide tools for manipulating images, mathematical points, lines, circles, and ellipses. Since these tools will probably be used again in the future, a prime consideration was balancing speed against portability in our design. We received a specification for the functions and structures needed. This specification included descriptions of structs, such as their data fields and types, and also function descriptions and prototypes.
One of the algorithms we implemented was Bresenham's Algorithm. This line-drawing algorithm is attractive because it uses integer arithmetic to draw fractional-slope lines, making it faster than a floating-point algorithm would be. Bresenham's Algorithm works by calculating an integer error at each pixel, which increments with each step across. When the error passes a value of 0, the line steps up when it steps across, and the error is reset.
To draw circles and ellipses, we used an algorithm similar to Bresenham's Algorithm, but modified to increase the amount the error increments at each step to correspond to the curve of the circle. We then started drawing points in the third quadrant of the image to keep it mathematically correct, and then drew the mirrored points that corresponded to the original point on both sides of each axis. So we basically had eight sections of the circles being drawn until they all connected into a whole circle. For the ellipses this had to be done for the two regions that made up the ellipse. The same idea was being used, but it was just changed so that it only had four parts being drawn at once.

Here is the output of
assignment2a.c,
which demonstrates that all of the functions work correctly and adhere to
the specifications of the assignment.
This is a 3D line image of a car, which demonstrates the ability to draw
lines and ellipses with various colors.
1. Alex Benn and Andrew Frampton collaborated on this lab. We made an effort to split up the work evenly, so while Alex wrote up the image and line functions along with the ".h" files, Andrew dealt with the point, circle and ellipse functions.
2. API manual
We avoided the use of state variables, instead structuring the routines to pass everything needed by reference. In a situation requiring repeated access to a single object, such as image manipulation within a window, or tracking of variables within a 3D simulation, we would use state variables to simplify function calls and speed execution.
void Line_set2D(Line *l, int x0, int y0, int x1, int y1): Sets the startpoint (x0,y0) and endpoints (x1,y1) of the specified line l.
void Line_set(Line *l, Point ta, Point tb): sets the start and endpoints of the specified line using Points ta and tb.
void Line_draw(Line *l, Image *src, Pixel p): Draws line l onto the Image pointersrc, with the collor being determined by pixel p.
Image *Image_create(): Allocates a new empty image pointer.
Image *Image_init(int rows, int cols): Allocates a new Image pointer with space for an image of size(rows, cols).
void Image_free(Image *src): Deallocates the specified image and resets all of its fields.
Image *Image_read(char *filename): Reads an image from specified filename.
int Image_writePPM(Image *src, char *filename): Saves the source image to its given filename.
void Point_set2D(Point *p, double x, double y): Stores the specified x- and y-coordinates to Point p.
void Point_set(Point *p, double x, double y, double z, double h): Stores the specified 4-dimensional coordinates to a Point.
void Point_draw(Point *p, Image *src, Pixel c): Draws a Point to an Image using a specified color p.
void Point_copy(Point p, Point q): Copies the coordinates of one Point into another.
void Circle_set(Circle *c, Point tc, double tr): Sets the center and radius of the Circle to the specified point.
void Circle_draw(Circle *c, Image *src, Pixel p): Draws a Circle to an Image.
void circleMidpoint (Image *src, Pixel color, int xCenter, int yCenter, int radius): Uses the midpoint of the circle to determine the individual points to be drawn.
void circlePlotPoints (Image *src,Pixel p,int xCenter,int yCenter, int x,int y): Plots the specified point, along with the seven corresponding points reflected across the x- and y-axes.
void Ellipse_set(Ellipse *e, Point tc, double ta, double tb): Sets the the Radii and Midpoint of the ellipse.
void Ellipse_draw(Ellipse *e, Image *src, Pixel p): draws the ellipse.
void ellipseMidpoint (Image *src, Pixel color, int xCenter, int yCenter, int Rx, int Ry): Uses the Midpoint of the ellipse to determine the points to be drawn for both regions of the ellipse.
void ellipsePlotPoints (Image *src, Pixel p, int xCenter, int yCenter, int x, int y): Plots the specified point along with three correspondning points reflected across the x and y axis.
3. We drew all our lines from the bottom left hand corner rather than the middle. This assured that lines would be the correct length. For the circle and the ellipse we changed the algorithm to start in the 3rd quadrant so that it would all be mathemtically correct.To do this we also had to reverse the values of x and the radius for each and modified the error variable to accomodate the change in sign.
4. For the sake of our sanity we did not do any extensions for this project.