-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw4.elm
28 lines (24 loc) · 793 Bytes
/
hw4.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import PathFinding exposing (Simulation, sim0, simulate, initSim, drawSim)
import Collage exposing (collage)
import Element exposing (toHtml)
import Time exposing (Time, every, second)
import Html exposing (Html)
import Html.App exposing (program)
import Random exposing (Generator, generate)
type Action = Init Simulation | Tick Time
view : Simulation -> Html Action
view = drawSim >> collage 600 600 >> toHtml
update : Action -> Simulation -> (Simulation, Cmd Action)
update action sim =
( case action of
Init sim -> sim
Tick dt -> simulate sim
, if sim.restart > 0 then Cmd.none else generate Init initSim
)
main : Program Never
main = program
{ init = ( sim0, Cmd.none )
, view = view
, update = update
, subscriptions = always (every (second / 10) Tick)
}