[Haskell-cafe] Line drawing algorithm

CK Kashyap ck_kashyap at yahoo.com
Fri Jul 17 09:04:18 EDT 2009

Thanks Neil ... 

> Are you doing this to learn Haskell, learn about drawing lines, or to just get it implemented?  If either of the latter two, when drawing a straight line you shouldn't need to do floating point operations such as this:

Actually, my reasons are first and third.

>     newY = y1 + round (slope * (fromIntegral (newX - x1)))

> http://rosettacode.org/wiki/Bresenham%27s_line_algorithm#Haskell

Thanks for the link.

> As to how to cope with the dy > dx case in your code given the dx > dy case, you could just swap the x and y coords at the start, then swap back the x and y coords of all the output points afterwards.  Odd, but effective :-)
Slope would differ right for both case right?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090717/6cd7b316/attachment.html

More information about the Haskell-Cafe mailing list