COSC 286: Computer Graphics

Project 2
Fall 1998

Due: 6 October
5 points

a. Using the project template (ProjectTemplate.java) provided on the class web page, code the DDA algorithm from Hearn and Baker's book. Implement Bresenham's line drawing algorithm for the general case. Test the algorithms using the following code:

    ...
    for (i = 0; i <= 100; i+=10) {
      drawLineDDA(g, 50, 50, 0, i);
      drawLineDDA(g, 50, 50, i, 0);
      drawLineDDA(g, 50, 50, 100, i);
      drawLineDDA(g, 50, 50, i, 100);
    } // for
    for (i = 100; i <= 200; i+=10) {
      drawLineBresenham(g, 150, 150, 100, i);
      drawLineBresenham(g, 150, 150, i, 100);
      drawLineBresenham(g, 150, 150, 200, i);
      drawLineBresenham(g, 150, 150, i, 200);
    } // for
    ...

b. Time how long it takes for each algorithm to draw 200 lines with random endpoints. Print the timing results to the screen. To time code in Java, use the Date class. For example:

    Date start = new Date();
    // code to be timed
    Date end = new Date();
    long runtime = end.getTime() - start.getTime();

Create two separate files: project2a.java and project2b.java

Feel free to use the programming language of your choice. Hand in a disk with your source and executable by the start of class on the due date.