We started to build our graphics environment by defining few fundamental structures: Point_t, Color_t, and Image_t. Type Point_t contains the x and y coordinate of a pixel, type Color_t contains the RGB channels of a pixel, and type Image_t contains a pointer to the image's memory location and its dimensions. As to dealing with variables, we decided to implement our environment with local variables only. Compare to other methods of maintaining variables, passing all necessary variables into functions can be cumbersome. But it is a safeguard against unwanted changes to variables other functions depend on. Nevertheless, state variables and/or structures will be useful when structures become more complex.
PPM images have their origin located on the upper left hand corner. We used to following transformation on (x,y) so the origin is moved to the lower bottom corner:
After implementing a transformation in PlotPixel, these lines drawn are exact matches of their mathematical counter part assuming the horitonal is x and the vertical is y. Because the lower left-hand corner is the origin, the image itself is a rasterized representaion of the first quadrant.
The following are lines drawn with the Bresenham's algorithm.
![]() dx = 40, dy = 20 |
![]() dx = 20, dy = 40 |
![]() dx = -20, dy = 40 |
![]() dx = -40, dy = 20 |
![]() dx = -40, dy = -20 |
![]() dx = -20, dy = -40 |
![]() dx = 40, dy = -20 |
![]() dx = 20, dy = -40 |
Results from testbench.c:
Average line length = 102.9
98369 lines per second at clock speed of 665MHz
|
|