-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
268 lines (232 loc) · 7.89 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Number Counting Game</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 0;
padding: 0;
background: radial-gradient(white, #857b98);// #578a8a
justify-content: center;
height: 100vh;
}
#settings {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 250px;
padding: 20px;
overflow-y: auto;
background:linear-gradient(to right, #578a8a,#fff0);
z-index:98;
}
#settings.open {
transform: translateX(0);
}
#numberDisplay {
font-size: min(45vh, 45vw);
margin-top: 20px;
color: #183a5e;
opacity: 0;
font-weight: bold;
}
.zoomEffect {
animation: zoomEffect 0.2s ease;
}
@keyframes zoomEffect {
0% {
transform: scale(0);
opacity: 0;
}
10%{
transform: scale(0.5);
opacity: 0;
}
30%{
transform: scale(.7);
opacity: 0.4;
}
100% {
transform: scale(1);
opacity: 1;
}
}
#result {
font-size: 4em;
margin-top: 20px;
color: #183a5e;
transition: opacity 0.5s;
}
.sameNumber {
color: red;
}
button {
padding: 10px 20px;
font-size: 1em;
cursor: pointer;
background-color: #578a8a;
color: white;
border: none;
border-radius: 5px;
margin-top: 10px;
}
.hidden{
display:none !important;
}
#toggleSettingsButton {
position: fixed;
top:5px;
left:10px;
z-index:99;
background-color: #578a8a;
color: white;
border: none;
border-radius: 0 5px 5px 0;
padding: 10px 20px;
cursor: pointer;
}
</style>
</head>
<body>
<button id="toggleSettingsButton" onclick="toggleSettings()">Settings</button>
<div id="settings">
<br><br>
<h2>Settings</h2>
<label>
<input type="checkbox" id="showEvenAsMinus" checked> Show even numbers with minus
</label>
<br>
<label>
Number of numbers to show:
<input type="number" id="numberLimit" value="10" min="1">
</label>
<br>
<label>
Time between numbers (ms):
<input type="number" id="timeBetweenNumbers" value="650" min="100">
</label>
<br>
<label>
Waiting time before result (ms):
<input type="number" id="waitingTime" value="3000" min="100">
</label>
<br>
<label>
Sound:<br/>
<select id="soundOption">
<option value="square" selected>Square Wave</option>
<option value="sine">Sine Wave</option>
<option value="sawtooth">Sawtooth Wave</option>
<option value="triangle">Triangle Wave</option>
</select>
</label>
</div>
<div id="result"></div>
<div id="numberDisplay" ></div><br/>
<button onclick="startGame()" style="position: fixed;bottom: 10vh;left: 45vw;right: 45vw;">Start Game</button>
<script>
let numbers = [];
let currentIndex = 0;
let userCount = 0;
let timer;
let audioContext;
let previousNumber = null;
function toggleSettings() {
const settingsDiv = document.getElementById('settings');
settingsDiv.classList.toggle('hidden');
}
function startGame() {
const numberLimit = parseInt(document.getElementById('numberLimit').value);
const showEvenAsMinus = document.getElementById('showEvenAsMinus').checked;
const timeBetweenNumbers = parseInt(document.getElementById('timeBetweenNumbers').value);
const waitingTime = parseInt(document.getElementById('waitingTime').value);
numbers = generateRandomNumbers(numberLimit, showEvenAsMinus);
currentIndex = 0;
userCount = 0;
previousNumber = null;
document.getElementById('numberDisplay').innerText = '';
document.getElementById('numberDisplay').style.color = '';
document.getElementById('result').innerText = '';
audioContext = new (window.AudioContext || window.webkitAudioContext)();
displayNextNumber(timeBetweenNumbers, waitingTime);
}
function generateRandomNumbers(count, showEvenAsMinus) {
let nums = [];
for (let i = 0; i < count; i++) {
let num = Math.floor(Math.random() * 10) + 1;
if (showEvenAsMinus && num % 2 === 0) {
num = -num;
}
nums.push(num);
}
return nums;
}
function displayNextNumber(timeBetweenNumbers, waitingTime) {
if (currentIndex < numbers.length) {
const numberDisplay = document.getElementById('numberDisplay');
const currentNumber = numbers[currentIndex];
numberDisplay.innerText = currentNumber;
numberDisplay.classList.add('zoomEffect');
setTimeout(() => {
numberDisplay.classList.remove('zoomEffect');
}, 200);
/*
if (currentNumber === previousNumber) {
numberDisplay.classList.add('sameNumber');
} else {
numberDisplay.classList.remove('sameNumber');
}
*/
previousNumber = currentNumber;
playBeep();
numberDisplay.style.opacity = 0;
numberDisplay.style.transform = 'scale(0.5)';
setTimeout(() => {
numberDisplay.style.opacity = 1;
numberDisplay.style.transform = 'scale(1)';
}, 10);
currentIndex++;
timer = setTimeout(() => displayNextNumber(timeBetweenNumbers, waitingTime), timeBetweenNumbers);
} else {
showWaitingAnimation(waitingTime);
numberDisplay.innerText = "";
}
}
function showWaitingAnimation(waitingTime) {
const resultDiv = document.getElementById('result');
resultDiv.innerText = "Thinking...";
setTimeout(() => {
showResult();
}, waitingTime); // Wait for the specified time before showing the result
}
function playBeep() {
const soundOption = document.getElementById('soundOption').value;
const oscillator = audioContext.createOscillator();
const gainNode = audioContext.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioContext.destination);
oscillator.type = soundOption;
oscillator.frequency.setValueAtTime(440, audioContext.currentTime); // 440 Hz (A4)
gainNode.gain.setValueAtTime(1, audioContext.currentTime);
gainNode.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + 0.1);
oscillator.start();
oscillator.stop(audioContext.currentTime + 0.1);
}
function showResult() {
clearTimeout(timer);
const totalSum = numbers.reduce((sum, num) => sum + num, 0);
const resultDiv = document.getElementById('result');
const numberDisplay = document.getElementById('numberDisplay');
resultDiv.innerText = `Total Sum:`;
numberDisplay.innerHTML = `${totalSum}`;
numberDisplay.style.color = "#578a8a";
resultDiv.style.opacity = 1;
}
</script>
</body>
</html>