-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSevenSeg.elm
203 lines (180 loc) · 4.56 KB
/
SevenSeg.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
module SevenSeg exposing (sevenSeg)
import Html exposing (..)
import Html.Attributes exposing (..)
-- SEVEN SEGMENT DISPLAY
{-
A
-
B | | C
- D
E | | F
-
G
-}
type Orientation = Horizontal | Vertical
type State = On | Off
type alias Style =
{ width : Float
, height: Float
, colour : String
}
sevenSeg : Float -> Float -> String -> Int -> Html msg
sevenSeg width height colour number =
let
segStyle =
{ width = width
, height = height
, colour = colour
}
horizontalStyle =
[ ("display", "flex")
, ("justify-content", "center")
]
verticalStyle =
[ ("display", "flex")
, ("justify-content", "space-between")
]
in
Html.div
[ style <| sevenSegStyle segStyle ]
[ Html.div [ style horizontalStyle ] [ sevenSegA segStyle number ]
, Html.div [ style verticalStyle ] [ sevenSegB segStyle number, sevenSegC segStyle number ]
, Html.div [ style horizontalStyle ] [ sevenSegD segStyle number ]
, Html.div [ style verticalStyle ] [ sevenSegE segStyle number, sevenSegF segStyle number ]
, Html.div [ style horizontalStyle ] [ sevenSegG segStyle number ]
]
sevenSegStyle : Style -> List (String, String)
sevenSegStyle style =
[ ("display", "inline-block")
, ("height", pixels <| style.height)
, ("width", pixels <| style.width)
]
-- SEGMENTS
sevenSegA style number =
segment Horizontal style
<| case number of
1 -> Off
2 -> On
3 -> On
4 -> Off
5 -> On
6 -> On
7 -> On
8 -> On
9 -> On
_ -> Off
sevenSegB style number =
segment Vertical style
<| case number of
1 -> Off
2 -> Off
3 -> Off
4 -> On
5 -> On
6 -> On
7 -> Off
8 -> On
9 -> On
_ -> Off
sevenSegC style number =
segment Vertical style
<| case number of
1 -> On
2 -> On
3 -> On
4 -> On
5 -> Off
6 -> Off
7 -> On
8 -> On
9 -> On
_ -> Off
sevenSegD style number =
segment Horizontal style
<| case number of
1 -> Off
2 -> On
3 -> On
4 -> On
5 -> On
6 -> On
7 -> Off
8 -> On
9 -> On
_ -> Off
sevenSegE style number =
segment Vertical style
<| case number of
1 -> Off
2 -> On
3 -> Off
4 -> Off
5 -> Off
6 -> On
7 -> Off
8 -> On
9 -> Off
_ -> Off
sevenSegF style number =
segment Vertical style
<| case number of
1 -> On
2 -> Off
3 -> On
4 -> On
5 -> On
6 -> On
7 -> On
8 -> On
9 -> On
_ -> Off
sevenSegG style number =
segment Horizontal style
<| case number of
1 -> Off
2 -> On
3 -> On
4 -> Off
5 -> On
6 -> On
7 -> Off
8 -> On
9 -> On
_ -> Off
segment : Orientation -> Style -> State -> Html msg
segment orientation segStyle state =
case orientation of
Horizontal ->
Html.div
[ style <| segmentStyle orientation segStyle state ]
[]
Vertical ->
Html.div
[ style <| segmentStyle orientation segStyle state ]
[]
segmentStyle : Orientation -> Style -> State -> List ( String, String )
segmentStyle orientation style state =
let
segmentWidth = toFloat <| ceiling <| style.height/16
in
[ ("display", "inline-block")
, case orientation of
Horizontal -> ("height", pixels <| segmentWidth)
Vertical -> ("height", pixels <| (style.height-segmentWidth*3)/2 - 2)
, case orientation of
Horizontal -> ("width", pixels <| style.width - (4*segmentWidth))
Vertical -> ("width", pixels <| segmentWidth)
, case state of
On -> ("background-color", style.colour)
Off -> ("background-color", "#080808")
, case orientation of
Horizontal -> ("margin", pixels <| 0)
Vertical -> ("margin", pixels <| 1)
, case state of
On -> ("box-shadow", "0px 0px 4px 1.5px " ++ style.colour)
Off -> ("box-shadow", "none")
]
-- OTHER
pixels : Float -> String
pixels number =
toString number ++ "px"