Skip to content

Commit 33696bb

Browse files
committed
switch to elm-0.19
1 parent a449747 commit 33696bb

File tree

9 files changed

+213
-11696
lines changed

9 files changed

+213
-11696
lines changed

Diff for: .gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
elm.min.js linguist-vendored

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
elm-stuff/
2+
elm.js
3+

Diff for: LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2016 Aleksey Pirogov (aka astynax)
1+
Copyright (c) 2019 Aleksey Pirogov (aka astynax)
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
44

Diff for: Main.elm

+79-67
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,82 @@
1-
module Main exposing (..)
1+
module Main exposing (main)
22

3-
import Color exposing (..)
3+
import Browser
4+
import Browser.Dom
5+
import Browser.Events
46
import Collage exposing (..)
5-
import Date exposing (Date)
6-
import Element exposing (toHtml)
7-
import Html exposing (Html, program)
7+
import Collage.Layout
8+
import Collage.Render
9+
import Color exposing (black, green, lightGreen, lightRed, lightYellow, red, yellow)
10+
import Html exposing (Html)
811
import List exposing (filterMap)
912
import Platform.Cmd
1013
import Platform.Sub
1114
import Task
12-
import Time exposing (every, second)
13-
import Window exposing (Size)
15+
import Time exposing (Posix)
1416

1517

1618
type Msg
17-
= Resize Size
18-
| Tick Date
19+
= Resize Float Float
20+
| Tick Posix
21+
| Here Time.Zone
1922

2023

2124
type alias Model =
22-
( ( Int, Int ), Date )
25+
{ width : Float
26+
, height : Float
27+
, date : Posix
28+
, zone : Time.Zone
29+
}
2330

2431

25-
main : Program Never Model Msg
32+
main : Program () Model Msg
2633
main =
27-
program
28-
{ init = init
34+
Browser.element
35+
{ init = always init
2936
, update = update
30-
, subscriptions = always <| subscriptions
37+
, subscriptions = always subscriptions
3138
, view = view
3239
}
3340

3441

3542
init : ( Model, Cmd Msg )
3643
init =
37-
( ( ( 0, 0 ), Date.fromTime 0 )
44+
( { width = 100
45+
, height = 100
46+
, date = Time.millisToPosix 0
47+
, zone = Time.utc
48+
}
3849
, Cmd.batch
39-
[ Task.perform Resize Window.size
40-
, Task.perform Tick Date.now
50+
[ Task.perform (\vp -> Resize vp.viewport.width vp.viewport.height)
51+
Browser.Dom.getViewport
52+
, Task.perform Tick Time.now
53+
, Task.perform Here Time.here
4154
]
4255
)
4356

4457

4558
subscriptions : Sub Msg
4659
subscriptions =
4760
Sub.batch
48-
[ Window.resizes Resize
49-
, every (10 * second) (Tick << Date.fromTime)
61+
[ Browser.Events.onResize (\w h -> Resize (toFloat w) (toFloat h))
62+
, Time.every (10 * 1000) Tick
5063
]
5164

5265

5366
view : Model -> Html Msg
54-
view ( ( w, h ), date ) =
55-
let
56-
width =
57-
toFloat w
58-
59-
height =
60-
toFloat h
61-
in
62-
toHtml <|
63-
collage w
64-
h
65-
[ filled black <| rect width height
66-
, clock (min width height) ( Date.hour date, Date.minute date )
67-
]
67+
view model =
68+
Collage.Render.svgBox
69+
( model.width
70+
, model.height
71+
)
72+
<|
73+
Collage.Layout.stack
74+
[ clock (min model.width model.height)
75+
( Time.toHour model.zone model.date
76+
, Time.toMinute model.zone model.date
77+
)
78+
, filled (uniform black) <| rectangle model.width model.height
79+
]
6880

6981

7082

@@ -92,7 +104,7 @@ view ( ( w, h ), date ) =
92104
-}
93105

94106

95-
clock : Float -> ( Int, Int ) -> Form
107+
clock : Float -> ( Int, Int ) -> Collage a
96108
clock size ( h, m ) =
97109
let
98110
ledSize =
@@ -113,56 +125,56 @@ clock size ( h, m ) =
113125
led p c1 c2 x y =
114126
if p then
115127
Just
116-
(move ( x, y ) <|
128+
(shift ( x, y ) <|
117129
group
118-
[ filled c1 <| circle ledSize
119-
, filled c2 <| circle <| ledSize * 0.8
130+
[ filled (uniform c1) <| circle ledSize
131+
, filled (uniform c2) <| circle <| ledSize * 0.8
120132
]
121133
)
134+
122135
else
123136
Nothing
124137

125-
gtt12 =
126-
h >= 12
127-
128138
hh =
129-
h % 12
139+
modBy 12 h
130140

131141
h3 =
132-
h % 3
142+
modBy 3 h
133143

134144
m5 =
135-
(m % 15) // 5
145+
modBy 15 m // 5
136146

137147
m1 =
138-
m % 5
148+
modBy 5 m
139149
in
140-
group <|
141-
filterMap identity <|
142-
[ led (hh >= 3) green lightGreen d3_10 d3_10
143-
, led (hh >= 9) green lightGreen -d3_10 d3_10
144-
, led (hh >= 6) green lightGreen 0 d1_5
145-
, led (gtt12) green lightGreen 0 d2_5
146-
, led (m >= 15) green lightGreen d3_10 -d3_10
147-
, led (m >= 45) green lightGreen -d3_10 -d3_10
148-
--, led (m >= 60) green lightGreen 0 -d1_5 -- 60min newer happen
149-
, led (m >= 30) green lightGreen 0 -d2_5
150-
, led (h3 > 0) red lightRed -d1_10 d3_10
151-
, led (h3 > 1) red lightRed d1_10 d3_10
152-
, led (m5 > 0) red lightRed -d1_10 -d3_10
153-
, led (m5 > 1) red lightRed d1_10 -d3_10
154-
, led (m1 > 0) yellow lightYellow -d3_10 0
155-
, led (m1 > 1) yellow lightYellow -d1_10 0
156-
, led (m1 > 2) yellow lightYellow d1_10 0
157-
, led (m1 > 3) yellow lightYellow d3_10 0
158-
]
150+
group <|
151+
filterMap identity <|
152+
[ led (hh >= 3) green lightGreen d3_10 d3_10
153+
, led (hh >= 9) green lightGreen -d3_10 d3_10
154+
, led (hh >= 6) green lightGreen 0 d1_5
155+
, led (h >= 12) green lightGreen 0 d2_5
156+
, led (m >= 15) green lightGreen d3_10 -d3_10
157+
, led (m >= 45) green lightGreen -d3_10 -d3_10
158+
, led (m >= 30) green lightGreen 0 -d2_5
159+
, led (h3 > 0) red lightRed -d1_10 d3_10
160+
, led (h3 > 1) red lightRed d1_10 d3_10
161+
, led (m5 > 0) red lightRed -d1_10 -d3_10
162+
, led (m5 > 1) red lightRed d1_10 -d3_10
163+
, led (m1 > 0) yellow lightYellow -d3_10 0
164+
, led (m1 > 1) yellow lightYellow -d1_10 0
165+
, led (m1 > 2) yellow lightYellow d1_10 0
166+
, led (m1 > 3) yellow lightYellow d3_10 0
167+
]
159168

160169

161170
update : Msg -> Model -> ( Model, Cmd Msg )
162-
update msg ( size, date ) =
171+
update msg model =
163172
case msg of
164-
Resize s ->
165-
( ( ( s.width, s.height ), date ), Cmd.none )
173+
Resize w h ->
174+
( { model | width = w, height = h }, Cmd.none )
166175

167176
Tick d ->
168-
( ( size, d ), Cmd.none )
177+
( { model | date = d }, Cmd.none )
178+
179+
Here z ->
180+
( { model | zone = z }, Cmd.none )

Diff for: Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
elm.min.js: elm.js
2+
closure-compiler elm.js > elm.min.js
3+
4+
elm.js: Main.elm
5+
elm make Main.elm --optimize --output=elm.js

Diff for: elm-package.json

-17
This file was deleted.

Diff for: elm.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"type": "application",
3+
"source-directories": [
4+
"."
5+
],
6+
"elm-version": "0.19.0",
7+
"dependencies": {
8+
"direct": {
9+
"avh4/elm-color": "1.0.0",
10+
"elm/browser": "1.0.1",
11+
"elm/core": "1.0.2",
12+
"elm/html": "1.0.0",
13+
"elm/time": "1.0.0",
14+
"timjs/elm-collage": "2.0.2"
15+
},
16+
"indirect": {
17+
"elm/json": "1.1.3",
18+
"elm/svg": "1.0.1",
19+
"elm/url": "1.0.0",
20+
"elm/virtual-dom": "1.0.2",
21+
"elm-community/basics-extra": "4.0.0"
22+
}
23+
},
24+
"test-dependencies": {
25+
"direct": {},
26+
"indirect": {}
27+
}
28+
}

0 commit comments

Comments
 (0)