class Bitmap
def draw_line(x1, y1, x2, y2)
color = Color.new(255, 255, 255, 255)
if x1 == x2
x = x1
for y in (y1 < y2 ? y1..y2 : y2..y1)
set_pixel(x, y, color)
end
else
a = (y2-y1)/(x2-x1).to_f
if -1 < a and a < 1
for x in (x1 < x2 ? x1..x2 : x2..x1)
y = a * (x - x1) + y1
set_pixel(x, y, color)
end
else
for y in (y1 < y2 ? y1..y2 : y2..y1)
x = (y - y1) / a + x1
set_pixel(x, y, color)
end
end
end
end
end