Computer Graphics – Practices and Principles 2ed
Last active
December 23, 2015 23:29
-
-
Save reinh/6710417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | A scan-conversion algorithm for drawing lines on integral coordinate | |
-- systems. Returns the list of coordinates that should be filled to draw | |
-- the line from point to point. | |
line :: (Integral a) => V2 a -> V2 a -> [V2 a] | |
line p p' = fmap near [0..end] where | |
end = case abs (p - p') of V2 dx dy -> max dx dy | |
near i = round <$> lerp (i % end) | |
(fmap fromIntegral p') | |
(fmap fromIntegral p) | |
-- From Linear.Vector | |
-- | Linearly interpolate between two vectors. | |
lerp :: Num a => a -> f a -> f a -> f a | |
lerp alpha u v = alpha *^ u ^+^ (1 - alpha) *^ v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> printLine $ line (V2 0 0) (V2 13 25) | |
◼ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ | |
◻ ◼ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ | |
◻ ◼ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ | |
◻ ◻ ◼ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ | |
◻ ◻ ◼ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ | |
◻ ◻ ◻ ◼ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ | |
◻ ◻ ◻ ◼ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ | |
◻ ◻ ◻ ◻ ◼ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ | |
◻ ◻ ◻ ◻ ◼ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ | |
◻ ◻ ◻ ◻ ◻ ◼ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ | |
◻ ◻ ◻ ◻ ◻ ◼ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ | |
◻ ◻ ◻ ◻ ◻ ◻ ◼ ◻ ◻ ◻ ◻ ◻ ◻ ◻ | |
◻ ◻ ◻ ◻ ◻ ◻ ◼ ◻ ◻ ◻ ◻ ◻ ◻ ◻ | |
◻ ◻ ◻ ◻ ◻ ◻ ◻ ◼ ◻ ◻ ◻ ◻ ◻ ◻ | |
◻ ◻ ◻ ◻ ◻ ◻ ◻ ◼ ◻ ◻ ◻ ◻ ◻ ◻ | |
◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◼ ◻ ◻ ◻ ◻ ◻ | |
◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◼ ◻ ◻ ◻ ◻ ◻ | |
◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◼ ◻ ◻ ◻ ◻ | |
◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◼ ◻ ◻ ◻ ◻ | |
◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◼ ◻ ◻ ◻ | |
◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◼ ◻ ◻ ◻ | |
◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◼ ◻ ◻ | |
◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◼ ◻ ◻ | |
◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◼ ◻ | |
◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◼ ◻ | |
◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◻ ◼ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment