-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimal_quiz.html
More file actions
398 lines (374 loc) · 15.3 KB
/
animal_quiz.html
File metadata and controls
398 lines (374 loc) · 15.3 KB
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SignConnect | Alphabet Quiz with Sign Recognition</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
<style>
body {
background: linear-gradient(135deg, #ffede7 0%, #e0f7fa 100%);
font-family: 'Poppins', sans-serif;
min-height: 100vh;
display: flex;
flex-direction: column;
overflow-x: hidden;
position: relative;
}
.main-content {
flex: 1;
padding-bottom: 50px;
}
.navbar {
background: linear-gradient(to right, #ff6e40, #26c6da);
position: sticky;
top: 0;
z-index: 1000;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.navbar-brand {
font-weight: 700;
font-size: 1.8rem;
color: #fff !important;
}
.nav-link {
color: #fff !important;
font-weight: 500;
transition: all 0.3s ease;
position: relative;
}
.nav-link:hover {
color: #e0f7fa !important;
}
.quiz-container {
background: #ffffff;
border-radius: 15px;
border: 2px solid transparent;
border-image: linear-gradient(to right, #ff6e40, #26c6da) 1;
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
padding: 30px;
max-width: 800px;
margin: 40px auto;
}
.quiz-question {
font-size: 1.5rem;
font-weight: 600;
color: #ff6e40;
text-align: center;
}
.webcam-feed {
width: 100%;
max-width: 400px;
border-radius: 10px;
border: 2px solid #26c6da;
margin: 20px auto;
position: relative;
}
#canvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.btn-sign {
background: linear-gradient(to right, #26c6da, #ff6e40);
color cruisecontrol: #fff;
border: none;
padding: 12px 30px;
border-radius: 25px;
transition: all 0.3s ease;
}
.btn-sign:hover {
background: linear-gradient(to right, #d81b60, #ff6e40);
transform: scale(1.05);
}
.correct {
animation: correctAnswer 0.5s ease;
background: #26c6da !important;
}
.incorrect {
animation: incorrectAnswer 0.5s ease;
background: #d81b60 !important;
}
@keyframes correctAnswer {
0% { transform: scale(1); }
50% { transform: scale(1.1); }
100% { transform: scale(1); }
}
@keyframes incorrectAnswer {
0% { transform: translateX(0); }
25% { transform: translateX(-10px); }
50% { transform: translateX(10px); }
75% { transform: translateX(-10px); }
100% { transform: translateX(0); }
}
.progress-bar {
height: 8px;
background-color: #26c6da;
border-radius: 4px;
}
.badge {
background: #d81b60;
color: #fff;
padding: 8px 15px;
border-radius: 20px;
margin: 5px;
}
.leaderboard {
background: #fff;
border-radius: 10px;
padding: 20px;
margin-top: 30px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.timer {
font-size: 1.2rem;
color: #ff6e40;
font-weight: 600;
}
.abstract-shape {
position: absolute;
opacity: 0.1;
z-index: -1;
}
.shape-1 {
top: 10%;
left: 5%;
width: 200px;
height: 200px;
background: radial-gradient(circle, #26c6da, transparent);
border-radius: 50%;
}
.shape-2 {
bottom: 20%;
right: 10%;
width: 150px;
height: 150px;
background: radial-gradient(circle, #d81b60, transparent);
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
</style>
</head>
<body>
<!-- Abstract Shapes -->
<div class="abstract-shape shape-1"></div>
<div class="abstract-shape shape-2"></div>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-dark shadow">
<div class="container">
<a class="navbar-brand d-flex align-items-center" href="index.html">
<img src="asset/logo.png" alt="Logo" class="logo-img">
<span>SignConnect</span>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="index.html">Home</a></li>
<li class="nav-item"><a class="nav-link" href="alphabet.html">Alphabet</a></li>
<li class="nav-item"><a class="nav-link" href="words.html">Words</a></li>
<li class="nav-item"><a class="nav-link" href="quizzes.html">Quizzes</a></li>
<li class="nav-item"><a class="nav-link" href="progress.html">Progress</a></li>
<li class="nav-item"><a class="nav-link" href="dashboard.html">Dashboard</a></li>
</ul>
</div>
</div>
</nav>
<!-- Main Content -->
<div class="container text-center main-content">
<div class="quiz-container" data-aos="fade-up">
<h1 class="text-primary mb-4">🔤 Sign Language Quiz</h1>
<div class="row mb-3">
<div class="col-md-4"><p><strong>Points:</strong> <span id="points">0</span></p></div>
<div class="col-md-4"><p><strong>Level:</strong> <span id="level">Beginner</span></p></div>
<div class="col-md-4"><p><strong>Timer:</strong> <span id="timer">20</span>s</p></div>
</div>
<div class="progress mb-4">
<div class="progress-bar" id="level-progress" role="progressbar" style="width: 0%;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<h3 class="quiz-question" id="question">Perform the sign for this letter!</h3>
<h4 id="target-letter" style="color: #d81b60; font-size: 2rem;"></h4>
<div class="webcam-feed">
<video id="video" autoplay></video>
<canvas id="canvas"></canvas>
</div>
<button class="btn btn-sign mt-3" id="sign-btn">Perform Sign</button>
<div id="feedback" class="mt-3"></div>
<button class="btn btn-primary mt-4" id="next-btn" style="display: none;">Next Question</button>
</div>
<!-- Badges -->
<div class="mt-4" data-aos="fade-up" data-aos-delay="200">
<h4>Your Achievements</h4>
<div id="badges"></div>
</div>
<!-- Leaderboard -->
<div class="leaderboard" data-aos="fade-up" data-aos-delay="400">
<h4>Leaderboard</h4>
<ul class="list-group" id="leaderboard">
<li class="list-group-item">1. Player1 - 500 pts</li>
<li class="list-group-item">2. Player2 - 450 pts</li>
<li class="list-group-item">3. Player3 - 400 pts</li>
</ul>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/canvas-confetti/1.6.0/confetti.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js"></script>
<script>
AOS.init({ duration: 800, once: true });
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
let currentQuestion = 0;
let points = 0;
let level = 'Beginner';
let timer = 20;
let timerInterval;
let badges = JSON.parse(localStorage.getItem('badges')) || [];
// Webcam setup
const video = document.getElementById('video');
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
async function setupWebcam() {
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
video.srcObject = stream;
video.onloadedmetadata = () => {
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
video.play();
};
}
// MediaPipe Hands setup
const hands = new Hands({
locateFile: (file) => `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`
});
hands.setOptions({
maxNumHands: 1,
modelComplexity: 1,
minDetectionConfidence: 0.5,
minTrackingConfidence: 0.5
});
hands.onResults(onResults);
function onResults(results) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
if (results.multiHandLandmarks) {
for (const landmarks of results.multiHandLandmarks) {
drawConnectors(ctx, landmarks, HAND_CONNECTIONS, { color: '#ff6e40', lineWidth: 5 });
drawLandmarks(ctx, landmarks, { color: '#26c6da', lineWidth: 2 });
}
}
}
// Simple sign recognition (placeholder)
function recognizeSign(landmarks) {
// Placeholder: Map landmarks to letters (requires trained model)
// Example: Check if thumb is up and other fingers are down for 'A'
if (!landmarks) return null;
const thumbTip = landmarks[4].y;
const indexTip = landmarks[8].y;
if (thumbTip < indexTip) return 'A'; // Simplified logic
return null; // Replace with actual model inference
}
// Initialize quiz
function initQuiz() {
setupWebcam();
hands.initialize();
loadQuestion();
updateStats();
updateBadges();
}
// Load question
function loadQuestion() {
const letter = letters[currentQuestion];
document.getElementById('question').textContent = 'Perform the sign for this letter!';
document.getElementById('target-letter').textContent = letter;
document.getElementById('sign-btn').disabled = false;
document.getElementById('feedback').innerHTML = '';
startTimer();
}
// Start timer
function startTimer() {
timer = 20;
document.getElementById('timer').textContent = timer;
clearInterval(timerInterval);
timerInterval = setInterval(() => {
timer--;
document.getElementById('timer').textContent = timer;
if (timer <= 0) {
clearInterval(timerInterval);
checkAnswer(null, letters[currentQuestion]);
}
}, 1000);
}
// Check answer
function checkAnswer(detected, correct) {
clearInterval(timerInterval);
const feedback = document.getElementById('feedback');
document.getElementById('sign-btn').disabled = true;
if (detected === correct) {
points += timer > 0 ? 10 + Math.floor(timer / 2) : 5;
feedback.innerHTML = '<p class="text-success">Correct! 🎉</p>';
confetti({ particleCount: 100, spread: 70, origin: { y: 0.6 } });
saveProgress(correct);
} else {
feedback.innerHTML = `<p class="text-danger">Incorrect. The correct sign was for ${correct}.</p>`;
}
updateStats();
checkBadges();
document.getElementById('next-btn').style.display = 'block';
}
// Save progress
function saveProgress(letter) {
const progress = JSON.parse(localStorage.getItem('alphabetProgress')) || {};
progress[letter] = { completed: true };
localStorage.setItem('alphabetProgress', JSON.stringify(progress));
}
// Update stats
function updateStats() {
document.getElementById('points').textContent = points;
const levelThresholds = { Beginner: 0, Intermediate: 100, Expert: 200 };
level = Object.keys(levelThresholds).find(l => points >= levelThresholds[l]) || 'Beginner';
document.getElementById('level').textContent = level;
const progress = Math.min((points % 100) || points, 100);
document.getElementById('level-progress').style.width = `${progress}%`;
document.getElementById('level-progress').setAttribute('aria-valuenow', progress);
}
// Check and award badges
function checkBadges() {
const completedCount = Object.values(JSON.parse(localStorage.getItem('alphabetProgress')) || {}).filter(p => p.completed).length;
if (completedCount >= 26 && !badges.includes('Alphabet Master')) {
badges.push('Alphabet Master');
localStorage.setItem('badges', JSON.stringify(badges));
updateBadges();
}
if (points >= 100 && !badges.includes('Sign Pro')) {
badges.push('Sign Pro');
localStorage.setItem('badges', JSON.stringify(badges));
updateBadges();
}
}
// Update badges display
function updateBadges() {
const badgesDiv = document.getElementById('badges');
badgesDiv.innerHTML = badges.length ? badges.map(b => `<span class="badge">${b}</span>`).join('') : '<p>No badges yet!</p>';
}
// Perform sign
document.getElementById('sign-btn').onclick = async () => {
const results = await hands.send({ image: video });
const detected = recognizeSign(results.multiHandLandmarks?.[0]);
checkAnswer(detected, letters[currentQuestion]);
};
// Next question
document.getElementById('next-btn').onclick = () => {
currentQuestion = (currentQuestion + 1) % letters.length;
document.getElementById('next-btn').style.display = 'none';
initQuiz();
};
// Initialize on page load
document.addEventListener('DOMContentLoaded', initQuiz);
</script>
</body>
</html>