-
Notifications
You must be signed in to change notification settings - Fork 40
/
Logo.elm
183 lines (161 loc) · 4.48 KB
/
Logo.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
module Main exposing (Model, Msg(..), Palette, init, main, palette, polygons, update, view)
import Animation exposing (px)
import Browser
import Color.Palette as Color exposing (green, purple, rgb)
import Html exposing (Html, div, h1)
import Html.Attributes as Attr
import Html.Events exposing (..)
import Svg exposing (..)
import Svg.Attributes exposing (..)
import Time
type alias Model =
{ styles : List Animation.State
, index : Int
}
type Msg
= EverybodySwitch
| Animate Animation.Msg
type alias Palette =
{ orange : Color.Color
, green : Color.Color
, lavender : Color.Color
, blue : Color.Color
}
palette : Palette
palette =
{ orange = rgb 240 173 0
, green = rgb 127 209 59
, lavender = rgb 90 99 120
, blue = rgb 96 181 204
}
polygons : List (List Animation.Property)
polygons =
[ [ Animation.points
[ ( 161.649, 152.782 )
, ( 231.514, 82.916 )
, ( 91.783, 82.916 )
]
, Animation.fill palette.orange
]
, [ Animation.points
[ ( 8.867, 0 )
, ( 79.241, 70.375 )
, ( 232.213, 70.375 )
, ( 161.838, 0 )
]
, Animation.fill palette.green
]
, [ Animation.points
[ ( 323.298, 143.724 )
, ( 323.298, 0 )
, ( 179.573, 0 )
]
, Animation.fill palette.blue
]
, [ Animation.points
[ ( 152.781, 161.649 )
, ( 0, 8.868 )
, ( 0, 314.432 )
]
, Animation.fill palette.lavender
]
, [ Animation.points
[ ( 255.522, 246.655 )
, ( 323.298, 314.432 )
, ( 323.298, 178.879 )
]
, Animation.fill palette.orange
]
, [ Animation.points
[ ( 161.649, 170.517 )
, ( 8.869, 323.298 )
, ( 314.43, 323.298 )
]
, Animation.fill palette.blue
]
]
update : Msg -> Model -> ( Model, Cmd Msg )
update action model =
case action of
EverybodySwitch ->
let
wrappedIndex =
if List.length model.styles < model.index then
model.index - List.length model.styles
else
model.index
newStyles =
List.drop wrappedIndex polygons ++ List.take wrappedIndex polygons
in
( { model
| index = wrappedIndex + 1
, styles =
List.map3
(\i style newStyle ->
Animation.interrupt
[ Animation.wait (Time.millisToPosix (i * 50))
, Animation.to newStyle
]
style
)
(List.range 0 (List.length model.styles))
model.styles
newStyles
}
, Cmd.none
)
Animate time ->
( { model
| styles = List.map (Animation.update time) model.styles
}
, Cmd.none
)
view : Model -> Html Msg
view model =
div
[ onClick EverybodySwitch
, Attr.style "margin" "200px auto"
, Attr.style "width" "500px"
, Attr.style "height" "500px"
, Attr.style "cursor" "pointer"
]
[ h1 [] [ text "Click to morph!" ]
, svg
[ version "1.1"
, x "0"
, y "0"
, viewBox "0 0 323.141 322.95"
]
<|
[ rect
[ fill "#7FD13B"
, x "192.99"
, y "107.392"
, width "107.676"
, height "108.167"
, transform "matrix(0.7071 0.7071 -0.7071 0.7071 186.4727 -127.2386)"
]
[]
, Svg.g []
(List.map (\poly -> polygon (Animation.render poly) []) model.styles)
]
]
init : ( Model, Cmd Msg )
init =
( { styles = List.map Animation.style polygons
, index = 1
}
, Cmd.none
)
main : Program () Model Msg
main =
Browser.element
{ init = always init
, view = view
, update = update
, subscriptions =
\model ->
Animation.subscription
Animate
model.styles
}