Skip to content

Instantly share code, notes, and snippets.

@JoelQ
Created August 11, 2017 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoelQ/d8885a64b4d63187f633b8eecadc7940 to your computer and use it in GitHub Desktop.
Save JoelQ/d8885a64b4d63187f633b8eecadc7940 to your computer and use it in GitHub Desktop.
delay : Time -> a -> Cmd a
delay t x =
Task.perform (always x) <| Process.sleep t
cmd : msg -> Cmd msg
cmd msg =
Task.perform (always msg) (Task.succeed msg)
initSeed = 100
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
InitForest forest ->
let
newNum = Random.step (Random.int 0 100) initSeed
in
( { model | forest = forest, probabilities = newNum, ready = True }
, delay (Time.second*550) (Tick newNum)
)
Tick num ->
let
newNum = Random.step (Random.int 0 100) num
in
if model.running && model.ready then
( { model | forest = incrementForest model, ready = False }, delay (Time.Second*500) (Tick newNum)
)
else
( model, Cmd.none )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment