-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.elm
More file actions
70 lines (60 loc) · 1.49 KB
/
Main.elm
File metadata and controls
70 lines (60 loc) · 1.49 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module Main exposing (..)
import Array exposing (Array)
import Browser
import Browser.Dom exposing (getViewport)
import Browser.Events
import Random
import Task
import Examples exposing (orbit, slingshot)
import Model exposing (Model, Lifecycle (..))
import Msg exposing (Msg (..), update)
import Physics exposing (advanceUniverse)
import View exposing (view)
updateWindowDimensions : Result err Browser.Dom.Viewport -> Msg
updateWindowDimensions res =
case res of
Ok viewport ->
ResizeWindow
( round viewport.viewport.width )
( round viewport.viewport.height )
Err msg ->
NoOp
starField : Random.Generator ( List ( Float, Float ) )
starField =
Random.list 150
( Random.pair ( Random.float 0 1000 ) ( Random.float 0 1000 )
)
init : ( Model, Cmd Msg )
init =
( { lifecycle = Welcome
, window = { width = 1000, height = 1000 }
, stars = []
}
, Cmd.batch
[ Task.attempt updateWindowDimensions Browser.Dom.getViewport
, Random.generate MakeStars starField
]
)
-- SUBS
animationTick : Model -> Sub Msg
animationTick model =
case model.lifecycle of
Welcome ->
Sub.none
Run _ ->
Browser.Events.onAnimationFrameDelta Tick
---- PROGRAM ----
main : Program () Model Msg
main =
Browser.element
{ view = view
, init = \_ -> init
, update = update
, subscriptions =
( \model ->
Sub.batch
[ animationTick model
, Browser.Events.onResize ResizeWindow
]
)
}