Guest
Public paste!

Fourth

By: a guest | Dec 22nd, 2009 | Syntax: C++ | Size: 0.49 KB | Hits: 1,606 | Expires: Never
Copy text to clipboard
  1. /*
  2. ** Author:      Nicholas Forysinski
  3. */
  4.  
  5. /*
  6. ** drawLine
  7. **
  8. ** Draw a line from vertex (x0,y0) to vertex (x1,y1) using
  9. ** the midpoint line algorithm (as discussed in class).
  10. */
  11.  
  12. void drawLine {
  13.  
  14.   if( dx > dy ) {
  15.    
  16.     x = x0
  17.     foreach step until x>=x1 {
  18.      
  19.       draw a pixel
  20.       adjust d and y values
  21.      
  22.     }
  23.    
  24.   } else {
  25.  
  26.     y = y0
  27.     for each step while y != y1 {
  28.  
  29.       draw a pixel
  30.       adjust d and x values
  31.      
  32.     }
  33.    
  34.   }
  35.  
  36. }