/
Update.elm
125 lines (98 loc) · 3.33 KB
/
Update.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
module WaveClock.Update exposing (Modifier(..), modify, tick)
import Color exposing (hsla)
import Perlin exposing (noise)
import Time exposing (Posix)
import WaveClock.Model exposing (Model)
type Modifier
= RadNoise
| AngNoise
| Radius
| Step
| Delay
| Hue
| Saturation
| Lightness
tick : Posix -> Model -> Model
tick time model =
let
timeInt =
Time.posixToMillis time
in
if model.modifiers.delay == 1 || timeInt - (round <| model.modifiers.delay * 1000) < model.lastTick then
model
else
let
imageWidth =
model.window.width - 200
radNoise =
model.angNoise + 0.005
radius =
(noise ( radNoise * model.modifiers.radNoise, 0, 0 ) model.seed * 550 * model.modifiers.radius) + 1
angNoise =
model.angNoise + 0.005
baseAngleStep =
6 * model.modifiers.step
baseAngle =
model.angle
+ (noise ( model.angNoise * model.modifiers.angNoise, 0, 0 ) model.seed * baseAngleStep)
- 3
angle =
if baseAngle > 360 then
baseAngle - 360
else if baseAngle < 0 then
baseAngle + 360
else
baseAngle
( xNoise, yNoise ) =
( model.xNoise + 0.01
, model.yNoise + 0.01
)
( centerX, centerY ) =
( imageWidth / 2 + (noise ( xNoise, 0, 0 ) model.seed * 100) - 50
, model.window.height / 2 + (noise ( yNoise, 0, 0 ) model.seed * 100) - 50
)
rad =
radians angle
oppRad =
rad + pi
in
{ model
| angle = angle
, angNoise = angNoise
, radNoise = radNoise
, xNoise = xNoise
, yNoise = yNoise
, lines =
model.lines
++ [ { x1 = centerX + (radius * cos rad)
, y1 = centerY + (radius * sin rad)
, x2 = centerX + (radius * cos oppRad)
, y2 = centerY + (radius * sin oppRad)
, color = hsla model.modifiers.hue model.modifiers.saturation model.modifiers.lightness (60 / 255)
}
]
, lastTick = timeInt
}
modify : Model -> Modifier -> Float -> Model
modify model mod val =
let
modifiers =
model.modifiers
in
case mod of
RadNoise ->
{ model | modifiers = { modifiers | radNoise = Debug.log "Val" <| val * 2 } }
AngNoise ->
{ model | modifiers = { modifiers | angNoise = val * 2 } }
Radius ->
{ model | modifiers = { modifiers | radius = val * 2 } }
Step ->
{ model | modifiers = { modifiers | step = val * 2 } }
Delay ->
{ model | modifiers = { modifiers | delay = val } }
Hue ->
{ model | modifiers = { modifiers | hue = val } }
Saturation ->
{ model | modifiers = { modifiers | saturation = val } }
Lightness ->
{ model | modifiers = { modifiers | lightness = val } }