Created
November 10, 2014 02:57
-
-
Save DanielCollins/9828d0b4f4ef6dac7856 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
import qualified Haste.Graphics.Canvas as C | |
import qualified Haste as H | |
indices :: [(Int, Int)] | |
indices = [(i, j) | i <- [0 .. 2], j <- [0 .. 2]] | |
strike :: C.Point -> Double -> C.Picture () | |
strike (x, y) width = | |
let margin = 0.1 * width | |
farSide = width - margin | |
left = x + margin | |
right = x + farSide | |
top = y + margin | |
bottom = y + farSide | |
in C.color (C.RGB 255 0 0) $ do | |
C.stroke $ C.line (right, top) (left, bottom) | |
draw :: Double -> C.Picture () | |
draw width = | |
do | |
_ <- sequence $ map drawOne indices | |
-- sequence_ $ map drawOne indices | |
strike (20, 20) 80 | |
where | |
cellWidth = width / 3 | |
drawOne (x, y) = | |
strike (offset x, offset y) cellWidth | |
offset i | |
| i == 0 = 0 | |
| i == 1 = width / 3 | |
| otherwise = (width * 2) / 3 | |
main :: IO () | |
main = do | |
Just element <- H.elemById "canvas" | |
Just canvas <- C.getCanvas element | |
widthString <- H.getProp element "width" | |
C.render canvas $ draw (read widthString) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment