MIPS Graphics Library

The program was written in MARS virtual environment, and
uses the Bitmap display to give a visual representation of the code. Each
method uses 4 memory addresses to pass parameters, if any more are needed then
they are sent to the stack.
The “SetPixel” method is the simplest, it takes the X, Y and
colour of the pixel – calculates it position on the screen and then stores the
colour into the memory address into the location where the screen gets its
information.
The “DrawLine” method uses Bresenham’s Line algorithm. It
takes a start point and end point of the line as parameters, as well as the
colour. It then works out the gradient of the line, plots the first pixel, and
then adds the gradient again to get to the next pixel. This repeats until it
has reached the second point.
The “DrawRectangle” and “DrawPolygon” methods work in the
same way except they calculate where the lines need to be, before calling the
“DrawLine” method. I have also implemented a “FillRectangle” method which
simply draws a line from one side to the other.
Finally I also included “DrawCircle” and “FillCircle”
routines, these both use the Midpoint Circle Algorithm. “DrawCircle” plots 8
points at a time around the circle, calculated by getting the radius and
position of the midpoint; the 8 points then draw 45 degrees of the circle each,
until they meet and form a complete circle. The “FillCircle” routine is similar,
but instead of plotting 8 points, takes 4 points as start parameters and 4
points as end parameters, which are then passed into “DrawLine”.
Comments
Post a Comment