Homework 2,
Lining up in the Raster.
Short Description:
Derive, implement and test Bresenham's line algorithm.
This assignment is worth 30 points.
Goals
When you finish this homework, you should
- have learned Bresenham's algorithm.
- understand how line primitives are handled in a graphics package.
- understand the separation of a user program and a graphics package.
- have demonstrated your ability to use linear interpolation.
Formal Description
This program consists of four parts
- [5 points] Derive the case for Bresenham's algorithm where -1 ≤ m < 0
- [10 points] Derive the other two cases for Bresenham's algorithm.
- [10 points] Implement Bresenham's algorithm.
- [5 points] Implement liner interpolation of colors in your line algorithm.
For part 1, follow the discussion in the notes, but derive the case where the slope is negative. You should present your results in a professional manner.
For part 2, do the same but work with y as the axis of major change. You should present your results in a professional manner.
For part 3 and 4 you should start with the following code.
- HW2.html. This file provides a simple interface to drive the graphics system. You may add to this but please do not delete functionality.
- dragon.js. This is a datafile used in testing lines. I generated it from a C++ program that generated a svg file from previous years. There is no need to edit this file.
- LineTests.js. This file contains a series of javascript functions to test the line algorithm. You may add routines to this, but please do not remove functionality. This is an example of a file a user might create to employ a graphics package.
- Canvas.js a javascript file that implements the basics of a simple graphics package.
The entire collection is available in this tar file.
You should edit Canvas.js and replace the Line routine, which implements the brute force method with an implementation of Bresenham's algorithm. Your line routine should accept the two points and associated colors. It should
continue to work with the routines in LineTests.js except that a line with two different end point colors should have a smooth interpolation of these colors between the end points AND it should be MUCH faster.
Please use the other routines in this package. In particular, you should not write directly the the frameBuffer array, but should make calls to SetPoint.
You should add a routine or routines which interpolate colors between two points.
Documentation
Your interface should built in a html file. This file should contain documentation discussing the project, including information such as
- Problems encountered
- Interesting techniques employed
- Sources of information
- Collaborators
- Notes on additions
- Screen shots of interesting results.
Please use relative references to your code in the html file. This will allow me to extract the file in my local environment.
Extras
I find that I want to continue to play with simulations/visualizations of this type. Please do so, but only if you have sufficient time, do not enhance this, or any other project at the expense of your other classes.
If you do decide to continue some interesting additions might include
- Adding a fractal generator in the test code.
- Making a better data set for the test code.
- Anything else you think of.
Submission
When you have finished your assignment, please submit a tar file containing all
files needed for this project. Please do not post your project on line until after grades have been assigned.
In the same directory, place a document which contains your derivations. This should be in an known document format (pdf, Microsoft Word, libre office, or latex).
Submit your tar file as an attachment to a message to danbennett360@gmail.com. Please include your name, and the fact that this is homework 2 in the title of the message.