
4.9. Line drawing 157
∆x = x
2
− x
1
∆y = y
2
− y
1
δ = −∆x/2
set x = x
1
and y = y
1
draw pixel at (x, y) with color c
while x < x
2
do {
δ = δ + ∆y
i f δ ≥ 0 {
y = y + y
inc
δ = δ − ∆x
}
x = x + 1
draw pixel at (x, y) with color c
}
Listing 4.16: The basic integer differential line generator algorithm.
∆x = x
2
− x
1
∆y = y
2
− y
1
i f |∆x| > |∆y| {
i f ∆x < 0 {
swap x
2
↔ x
1
swap y
2
↔ y
1
}
i f y
2
> y
1
then y
inc
= 1
e ls e y
inc
= −1
Call the first octant algorithm
}
e ls e {
i f ∆y < 0 {
swap x
2
↔ x
1
swap y
2
↔ y
1
}
i f x
2
> x
1
then x
inc
= 1
e ls e x
inc
= −1
Call the second octant algorithm
}
Listing 4.17: Algorithm for the drawing of a n arbitrarily directed straight line in a
raster display.
are swapped, and ...