Last active
August 29, 2015 14:22
-
-
Save GlenDC/04b324bada8e41d599ca to your computer and use it in GitHub Desktop.
Draw Grid
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 Color exposing (..) | |
import Graphics.Collage exposing (..) | |
import Graphics.Element exposing (..) | |
import Window | |
main : Signal Element | |
main = | |
Signal.map render Window.dimensions | |
renderGridLine : Int -> Int -> Int -> Int -> Form | |
renderGridLine ax ay bx by = | |
traced (dashed red) (path ([(toFloat ax, toFloat ay), (toFloat bx, toFloat by)])) | |
renderGridLines : Int -> Int -> Int -> (Int -> Int -> Form) -> List Form | |
renderGridLines gridsz cellsz i renderLine = | |
if i == 0 then [] else | |
let j = i - 1 | |
pos = j * cellsz | |
in (renderLine pos gridsz) :: (renderGridLines gridsz cellsz j renderLine) | |
renderGrid : Int -> Int -> Int -> Int -> Element | |
renderGrid gridsz cellsz gx gy = | |
let renderHor = \pos sz -> renderGridLine pos 0 pos sz | |
renderVer = \pos sz -> renderGridLine 0 pos sz pos | |
grid = (renderGridLines gridsz cellsz gy renderHor) ++ | |
(renderGridLines gridsz cellsz gx renderVer) | |
in | |
collage gridsz gridsz grid | |
render : (Int, Int) -> Element | |
render (x, y) = | |
renderGrid 400 50 8 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment