CS 351 - Assignment 3:Graphics Primitives
Titobiloluwa Awe and Elena Kirillova
In this project, we created some various graphic primitives for building our graphics system. Some of the graphic primitives that we implemented in this project included lines, circles, ellipses, and polylines. We created different required images and were able to create a 3D looking image of a car.
Our first task was to implement Bresenham's algorithm for our line_draw() function and implement the midpoint circle and ellipse algorithms. We also implemented the flood-fill algorithm for filling in a shape as an extension.
In order to implement Bresenham's algorithm, we took the pseudo code and used the already implemented functions in our line.c file to draw a line. We checked to see if we were drawing a more vertical or horizontal line. For the circle, we used the midpoint circle algorithm on the link on the project page, but we implemented it starting from the quadrant, instead of the first quadrant. For the ellipse, we used the pseudo code from the lecture notes to implement the ellipse algorithm. Finally, for the flood algorithm, we had to first create a stack, push a point onto the stack and while the stack was not empty, add all of the neighbors that have not been colored.
Lines - Bresenham's algorithm
Here is the result of running test_lines.c:
Here is the output of the program:
The speed of drawing lines was not as fast at first. We had a lot of in-between check print statements and a couple of pre-writing out function calls. With them that speed was about twice as slow.
Circles and Ellipses
required picture #1:
required picture #2:
required picture #3:
car and spaceship:
Car program made use of our Line and Circle draw functions. New function box() was used.
Spaceship program used the Polyline and Line draw functions. New function parabola() was created, that drew a polyline of parabolic look, which was achieved by specifying y-coords of all points with a quadratic formula. Parabola can be scaled, stretched and moved around the image.
Our implementation of the Flood-fill algorithm was such that our function would take initial coordinates and two colors as an input. The coordinates defined what exactly you want to fill. So on the above images to fill the inside of the thingy we had to call the function with coordinates of that inside. There were two input colors: new and old. The algorithm looked at the pixels of specifically old color and colored them by the new color.
In conclusion, this was a very essential project because here we created very important graphic primitives that we will be using for projects in the future. This was a very interesting project because it tested our ability to convert pseudo code into real c code and our ability to understand complex algorithms. In general, this was a very interesting project.