|
|
Description
This applet demonstrates the line drawing algoriithm using
the Digital Differential Analyser (DDA) method.
Note: Click the 'Refresh' button before you begin.
Select any two points on the applet with mouse clicks. The 'ideal line' between the selected points is first drawn.
The 'pixel line' is then drawn using the DDA algorithm. Click the 'Refresh' button before selecting a new pair of points.
Code
(DDA Algorithm)
|
void line(int x1, int y1, int x2, int y2){ double m = (double)(y2-y1)/(x2-x1); double y = (double)y1; int iy; for (int x = x1 ; x <= x2 ; x++) { iy = (int)Math.round(y); setPixel (x, iy); y+ = m; } } |