-
Notifications
You must be signed in to change notification settings - Fork 0
/
Update.elm
68 lines (47 loc) · 1.54 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
module Update exposing (..)
import Color exposing (Color)
import Constants
import Math.Vector2 exposing (Vec2, vec2)
import Model exposing (..)
import Random.Pcg exposing (..)
type Msg
= ToggleDistance
| AddPoint ( Point, Seed )
update : Msg -> Model -> Model
update msg model =
case msg of
ToggleDistance ->
case model.distance of
Euclidean ->
{ model | distance = Manhattan }
Manhattan ->
{ model | distance = Euclidean }
AddPoint data ->
addPoint data model |> updateSeed data
addPoint : ( Point, Seed ) -> Model -> Model
addPoint random model =
{ model | points = Tuple.first random :: model.points }
updateSeed : ( Point, Seed ) -> Model -> Model
updateSeed random model =
{ model | seed = Tuple.second random }
randomPoint : Model -> ( Point, Seed )
randomPoint model =
step pointGenerator model.seed
pointGenerator : Generator Point
pointGenerator =
map Point coordinateGenerator |> andMap colorGenerator
coordinateGenerator : Generator Vec2
coordinateGenerator =
map2 vec2
(float Constants.coordinateBufferZone
(Constants.size - Constants.coordinateBufferZone)
)
(float Constants.coordinateBufferZone
(Constants.size - Constants.coordinateBufferZone)
)
randomColor : Model -> ( Color, Seed )
randomColor model =
step colorGenerator model.seed
colorGenerator : Generator Color
colorGenerator =
map3 Color.rgb (int 0 255) (int 0 255) (int 0 255)