Created
May 11, 2014 23:04
-
-
Save imeckler/ce24217c6c7d2f30b0e5 to your computer and use it in GitHub Desktop.
Elm example
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 Keyboard | |
| import List | |
| import Window | |
| import Color | |
| import Random | |
| input = dropRepeats Keyboard.space | |
| ticks = fps 30 | |
| stepBall delta { x, y, color } = {x = x + delta / 5, y = y, color = color} | |
| stepBalls (space, randBall, delta) balls = | |
| if space then randBall :: List.map (stepBall delta) balls | |
| else List.map (stepBall delta) balls | |
| randColor = lift3 Color.rgb (Random.range 0 255 ticks) (Random.range 0 255 ticks) (Random.range 0 255 ticks) | |
| randBall = lift2 (\f c -> {x=0, y=f * 400, color=c}) (Random.float ticks) randColor | |
| renderBall {x, y, color} = circle 8 |> filled color |> move (x, y) | |
| render (w, h) balls = collage w h (map renderBall balls) | |
| signalZip3 = lift3 (\x y z -> (x, y, z)) | |
| main = | |
| lift2 render Window.dimensions | |
| (foldp stepBalls [] (signalZip3 input randBall ticks)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment