Created
July 18, 2015 22:45
-
-
Save stefanbirkner/67599304788b53bf6f5f to your computer and use it in GitHub Desktop.
Paint H-Boxes
This file contains hidden or 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 Mouse | |
import Window | |
type alias Box = (Int,Int) | |
type alias Editor = { boxes: List Box } | |
main : Signal Element | |
main = start { boxes = [] } | |
start : Editor -> Signal Element | |
start editor = | |
Signal.map2 view Window.dimensions addBox | |
addBox : Signal Editor | |
addBox = | |
Signal.foldp (\(x,y) editor -> { editor | boxes <- (x,y) :: editor.boxes }) { boxes = [] } (Signal.sampleOn Mouse.clicks Mouse.position) | |
view : (Int,Int) -> Editor -> Element | |
view (width,height) editor = | |
let drawBox (x,y) = | |
ngon 4 20 | |
|> filled (hsla (toFloat x) 0.9 0.6 0.7) | |
|> move (toFloat x - toFloat width / 2, toFloat height / 2 - toFloat y) | |
|> rotate (toFloat x) | |
in | |
collage width height (List.map drawBox editor.boxes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment