Last active
August 29, 2015 14:01
-
-
Save bucketh3ad/cdeb54f1b32ca913299e to your computer and use it in GitHub Desktop.
Elm Scenes Example
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 Keyboard | |
import Mouse | |
mpos : Signal (Int,Int) | |
mpos = Mouse.position | |
kpos : Signal {x:Int,y:Int} | |
kpos = Keyboard.arrows | |
draw1 : (Int,Int) -> Element | |
draw1 (x,y) = collage 300 300 | |
[ rect 50 50 |> filled (blue) | |
,toForm (asText (x,y)) |> move (toFloat x - 150, toFloat -y + 150 ) | |
] | |
draw2 : {x:Int, y:Int} -> Element | |
draw2 ({x,y} as k) = collage 300 300 | |
[ rect 50 50 |> filled (red) |> move (toFloat x * 100, toFloat y * 100) | |
, toForm (asText (x,y)) | |
] | |
scene1 : Signal Element | |
scene1 = draw1 <~ mpos | |
scene2 : Signal Element | |
scene2 = draw2 <~ kpos | |
toggle : Signal Element -> Signal Element -> Signal Bool -> Signal Element | |
toggle s1 s2 i = | |
lift3 (,,) s1 s2 i |> lift (\(s1,s2,i) -> if i then s1 else s2) | |
main = toggle scene1 scene2 Mouse.isDown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment