-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
284 lines (245 loc) · 7.36 KB
/
index.html
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Seven-segment Display</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
text-align: center;
font-family: cursive;
background-color: #E6E6E6;
}
header, footer {
background-color: #404040;
color: #E6E6E6;
width: 100%;
height: 80px;
display: flex;
align-items: center;
justify-content: center;
}
main {
display: flex;
align-items: center;
justify-content: center;
}
.display {
background-color: #ccc;
padding: 10% 20%;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%)
}
#top {
width: 100px;
height: 100px;
margin: auto;
border: solid;
border-width: 10px 10px 5px;
background-color: #eFeFef;
}
#bottom {
width: 100px;
height: 100px;
margin: auto;
border: solid;
border-width: 5px 10px 10px;
background-color: #eFeFef;
}
button {
border: none;
outline: none;
width: 30px;
height: 30px;
margin-top: 20px;
}
footer {
position: absolute;
bottom: 0;
width: 100%;
}
@media screen and (min-width: 375px) {
.display {
padding: 10% 15%;
}
#top {
width: 130px;
height: 130px;
}
#bottom {
width: 130px;
height: 130px;
}
button {
width: 40px;
height: 40px;
}
}
@media screen and (min-height: 730px) {
.display {
padding: 15% 15%;
}
}
@media screen and (min-width: 700px) {
.display {
padding: 5% 20%;
}
#top {
width: 150px;
height: 150px;
}
#bottom {
width: 150px;
height: 150px;
}
button {
width: 50px;
height: 50px;
}
}
</style>
</head>
<body onload="booleanEquations()">
<header>
<h1>7-segment Display</h1>
</header>
<main>
<div class="display">
<div id="top"></div>
<div id="bottom"></div>
<div class="buttons" onclick="booleanEquations()">
<button id="b8">0</button>
<button id="b4">0</button>
<button id="b2">0</button>
<button id="b1">0</button>
</div>
</div>
</main>
<footer>
<p>Created By João Vitor Dias</p>
</footer>
<script>
var b1 = document.getElementById('b1')
var b2 = document.getElementById('b2')
var b4 = document.getElementById('b4')
var b8 = document.getElementById('b8')
var b1Press = 0
var b2Press = 0
var b4Press = 0
var b8Press = 0
var A = false
var B = false
var C = false
var D = false
var onButton = '#878787'
var offButton = '#e6e6e6'
function pressButton1() {
if(b1Press%2 == 0) {
b1.style.background = onButton
b1Press -= 1
D = true
b1.innerText = '1'
} else {
b1.style.background = offButton
b1Press -=1
D = false
b1.innerText = '0'
}
}
function pressButton2() {
if(b2Press%2 == 0) {
b2.style.background = onButton
b2Press -= 1
C = true
b2.innerText = '1'
} else {
b2.style.background = offButton
b2Press -=1
C = false
b2.innerText = '0'
}
}
function pressButton4() {
if(b4Press%2 == 0) {
b4.style.background = onButton
b4Press -= 1
B = true
b4.innerText = '1'
} else {
b4.style.background = offButton
b4Press -=1
B = false
b4.innerText = '0'
}
}
function pressButton8() {
if(b8Press%2 == 0) {
b8.style.background = onButton
b8Press -= 1
A = true
b8.innerText = '1'
} else {
b8.style.background = offButton
b8Press -=1
A = false
b8.innerText = '0'
}
}
function booleanEquations() {
var top = document.getElementById('top')
var bottom = document.getElementById('bottom')
var onDisplay = '#FF0000'
var offDisplay = '#e6e6e6'
var a = (!A && C || B && C || !B && !D || C &&!D || A && !C && !D || A && !B && !C || !A && B && D)
var b = (!A && !B || !B && !D || A && !C && D || !A && C && D || !A && !C && !D)
var c = (A && !B || !A && B || !A && !C || !A && D || !C && D)
var d = (A && !C || !A && !B && !D || B && C && !D || B && !C && D || !B && C && D)
var e = (A && B || A && C || !B && !D || C && !D )
var f = (A && !B || A && C || B && !D || !C && !D || !A && B && !C)
var g = (A && !B || A && D || C && !D || !A && B && !C || !A && !B && C || !B && C)
if(a)
top.style.borderTopColor = onDisplay
else
top.style.borderTopColor = offDisplay
if(b)
top.style.borderRightColor = onDisplay
else
top.style.borderRightColor = offDisplay
if(c)
bottom.style.borderRightColor = onDisplay
else
bottom.style.borderRightColor = offDisplay
if(d)
bottom.style.borderBottomColor = onDisplay
else
bottom.style.borderBottomColor = offDisplay
if(e)
bottom.style.borderLeftColor = onDisplay
else
bottom.style.borderLeftColor = offDisplay
if(f)
top.style.borderLeftColor = onDisplay
else
top.style.borderLeftColor = offDisplay
if(g) {
top.style.borderBottomColor = onDisplay
bottom.style.borderTopColor = onDisplay
} else {
top.style.borderBottomColor = offDisplay
bottom.style.borderTopColor = offDisplay
}
}
b1.onclick = pressButton1
b2.onclick = pressButton2
b4.onclick = pressButton4
b8.onclick = pressButton8
</script>
</body>
</html>