LINE DRAWING ALGORITHM
1. Get the co-ordinates of line segment (x1, y1) and (x2, y2)
2. dx = abs(x2-x1)
3. dy = abs(y2-y1)
4. p= 2 * dy - dx
5. if x1 > x2
x = y2
y = y2
xend = x1
else
x = x1
y = y1
xend = x2
6. set pixel(x, y)
7. while x < xend
if p < 0 then
x = x + 1;
y = y;
p = p + 2 * dy
else
y = y + 1;
x = x + 1;
p = p + 2 * ( dy - dx )
8. set pixel(x, y, 1)
9. STOP
No comments:
Post a Comment