-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo.elm
98 lines (88 loc) · 2.36 KB
/
Demo.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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import Color exposing (..)
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import Time exposing (..)
import Random exposing (..)
import Basics exposing (..)
import Window
import Plasma exposing (..)
import Hypnocorn exposing (..)
import Rotozoom exposing (..)
import Starfield
import SquareThing
import Html exposing (..)
import Html.Attributes exposing (..)
import Credits exposing (..)
type Effect = Rotozoom | Hypnocorn | Plasma | Starfield | Credits | SquareThing
type alias State =
{ effect : Effect
, effectStart : Float
, time : Float
, stars : Starfield.Stars
, squares : SquareThing.Squares
}
muzak : Element
muzak =
Html.audio [ src "muzak.mp3", preload "true", autoplay True ] []
|> toElement 1 1
initialState : State
initialState =
{ effect = Starfield
, effectStart = 0
, time = 0
, stars = Starfield.stars
, squares = SquareThing.initialSquares
}
updateState : Float -> State -> State
updateState time state =
let
effect = selectEffect (time / 1000)
effectStart =
if effect /= state.effect then
time
else
state.effectStart
in
{ state |
effect = effect,
effectStart = effectStart,
time = time,
stars = Starfield.update state.time state.stars,
squares = SquareThing.update state.time state.squares
}
selectEffect : Float -> Effect
selectEffect t =
if t < 15 then
Starfield
else if t < 45 then
Rotozoom
else if t < 60 then
Hypnocorn
else if t < 80 then
Plasma
else if t < 100 then
SquareThing
else
Credits
main : Signal Element
main =
Signal.map2 view (Signal.foldp updateState initialState (Signal.foldp (+) 0 (fps 60))) Window.dimensions
view : State -> (Int, Int) -> Element
view state (w, h) =
let
time = (state.time - state.effectStart)
effectView = case state.effect of
Hypnocorn ->
hypnocorn w h time
Starfield ->
Starfield.view state.stars (w, h)
Credits ->
credits w h time
Rotozoom ->
rotozoom w h time
Plasma ->
plasma w h time
SquareThing ->
SquareThing.view state.squares (w, h)
in
flow outward [effectView, muzak]