Spaces:
Running
Running
Update index.html
Browse files- index.html +53 -99
index.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>AI Vision -
|
| 7 |
|
| 8 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js" crossorigin="anonymous"></script>
|
| 9 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
|
|
@@ -69,22 +69,23 @@
|
|
| 69 |
height: 480px;
|
| 70 |
max-width: 90vw;
|
| 71 |
object-fit: cover;
|
| 72 |
-
transform: scaleX(-1);
|
| 73 |
}
|
| 74 |
|
|
|
|
| 75 |
.pose1-anim {
|
| 76 |
position: absolute;
|
| 77 |
-
|
| 78 |
border-radius: 8px;
|
| 79 |
z-index: 10;
|
| 80 |
border: 2px solid #eab308;
|
| 81 |
box-shadow: 0 0 15px rgba(234, 179, 8, 0.8);
|
| 82 |
pointer-events: none;
|
| 83 |
-
|
|
|
|
| 84 |
transform: scaleX(-1);
|
| 85 |
}
|
| 86 |
|
| 87 |
-
/* --- STYLING PANEL BIOMETRIC SCANNER --- */
|
| 88 |
#biometricContainer {
|
| 89 |
position: absolute;
|
| 90 |
top: 15px;
|
|
@@ -102,15 +103,13 @@
|
|
| 102 |
.bio-label { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; margin-top: 8px; margin-bottom: 2px;}
|
| 103 |
.bio-label:first-child { margin-top: 0; }
|
| 104 |
.bio-value { font-size: 18px; font-weight: bold; color: #f8fafc; }
|
| 105 |
-
|
| 106 |
-
/* Garis pemisah kecil di panel */
|
| 107 |
.divider { height: 1px; background-color: #334155; margin: 8px 0; }
|
| 108 |
</style>
|
| 109 |
</head>
|
| 110 |
<body>
|
| 111 |
|
| 112 |
-
<h2>🤖 AI Vision:
|
| 113 |
-
<p>
|
| 114 |
|
| 115 |
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 116 |
|
|
@@ -119,13 +118,10 @@
|
|
| 119 |
</div>
|
| 120 |
|
| 121 |
<div class="monitor-container">
|
| 122 |
-
<!-- Floating Panel Biometric Baru -->
|
| 123 |
<div id="biometricContainer">
|
| 124 |
<div class="bio-label">Kondisi Mood</div>
|
| 125 |
<div id="moodValue" class="bio-value">Menganalisis...</div>
|
| 126 |
-
|
| 127 |
<div class="divider"></div>
|
| 128 |
-
|
| 129 |
<div class="bio-label">Estimasi Anatomi</div>
|
| 130 |
<div id="genderValue" class="bio-value" style="color: #cbd5e1;">Memindai...</div>
|
| 131 |
</div>
|
|
@@ -161,22 +157,17 @@
|
|
| 161 |
document.getElementById('audio5')
|
| 162 |
];
|
| 163 |
|
| 164 |
-
|
|
|
|
|
|
|
| 165 |
let currentFaceLandmarks = null;
|
| 166 |
|
| 167 |
-
function getDistance(p1, p2) {
|
| 168 |
-
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
|
| 169 |
-
}
|
| 170 |
|
| 171 |
-
// --- FUNGSI ANALISIS WAJAH (MOOD & GENDER) ---
|
| 172 |
function analyzeFaceBiometrics(faceLandmarks) {
|
| 173 |
-
|
| 174 |
-
const
|
| 175 |
-
const
|
| 176 |
-
const topLip = faceLandmarks[13];
|
| 177 |
-
const bottomLip = faceLandmarks[14];
|
| 178 |
-
const leftEye = faceLandmarks[33];
|
| 179 |
-
const rightEye = faceLandmarks[263];
|
| 180 |
|
| 181 |
const mouthWidth = getDistance(leftMouth, rightMouth);
|
| 182 |
const mouthHeight = getDistance(topLip, bottomLip);
|
|
@@ -189,30 +180,16 @@
|
|
| 189 |
if (openRatio > 0.15) { moodText = "Terkejut 😲"; moodColor = "#a855f7"; }
|
| 190 |
else if (smileRatio > 0.52) { moodText = "Senang 😊"; moodColor = "#10b981"; }
|
| 191 |
|
| 192 |
-
|
| 193 |
-
const
|
| 194 |
-
const rightCheek = faceLandmarks[454];
|
| 195 |
-
const leftJaw = faceLandmarks[132];
|
| 196 |
-
const rightJaw = faceLandmarks[361];
|
| 197 |
|
| 198 |
const cheekWidth = getDistance(leftCheek, rightCheek);
|
| 199 |
const jawWidth = getDistance(leftJaw, rightJaw);
|
| 200 |
-
|
| 201 |
-
// Rumus Logika: Pria cenderung memiliki rahang yang lebih seimbang dengan pipi (lebar)
|
| 202 |
-
// Wanita cenderung memiliki rahang lebih tirus (rasio lebih kecil)
|
| 203 |
const jawToCheekRatio = jawWidth / cheekWidth;
|
| 204 |
|
| 205 |
let genderText = "Memindai..."; let genderColor = "#cbd5e1";
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
// Wajah yang rahangnya lebar (>0.76 dari pipi) diasumsikan maskulin.
|
| 209 |
-
if (jawToCheekRatio > 0.755) {
|
| 210 |
-
genderText = "Pria 👨";
|
| 211 |
-
genderColor = "#60a5fa"; // Biru Pria
|
| 212 |
-
} else {
|
| 213 |
-
genderText = "Wanita 👩";
|
| 214 |
-
genderColor = "#f472b6"; // Pink Wanita
|
| 215 |
-
}
|
| 216 |
|
| 217 |
return { moodText, moodColor, genderText, genderColor };
|
| 218 |
}
|
|
@@ -235,32 +212,23 @@
|
|
| 235 |
return null;
|
| 236 |
}
|
| 237 |
|
| 238 |
-
|
| 239 |
-
const faceMesh = new FaceMesh({locateFile: (file) => {
|
| 240 |
-
return `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${file}`;
|
| 241 |
-
}});
|
| 242 |
faceMesh.setOptions({ maxNumFaces: 1, refineLandmarks: true, minDetectionConfidence: 0.7, minTrackingConfidence: 0.7 });
|
| 243 |
|
| 244 |
faceMesh.onResults((results) => {
|
| 245 |
-
|
| 246 |
-
currentFaceLandmarks = results.multiFaceLandmarks[0];
|
| 247 |
-
} else {
|
| 248 |
-
currentFaceLandmarks = null;
|
| 249 |
-
}
|
| 250 |
});
|
| 251 |
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
}
|
| 256 |
-
hands.setOptions({ maxNumHands: 2, modelComplexity: 1, minDetectionConfidence: 0.7, minTrackingConfidence: 0.7 });
|
| 257 |
|
| 258 |
hands.onResults((results) => {
|
| 259 |
canvasCtx.save();
|
| 260 |
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
| 261 |
canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height);
|
| 262 |
|
| 263 |
-
// --- RENDER WAJAH ---
|
| 264 |
if (currentFaceLandmarks) {
|
| 265 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_TESSELATION, {color: '#06b6d4', lineWidth: 0.5});
|
| 266 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYE, {color: '#ec4899', lineWidth: 2});
|
|
@@ -271,9 +239,9 @@
|
|
| 271 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LIPS, {color: '#ec4899', lineWidth: 2});
|
| 272 |
}
|
| 273 |
|
| 274 |
-
// --- RENDER TANGAN ---
|
| 275 |
let detectedPosesThisFrame = [];
|
| 276 |
-
|
|
|
|
| 277 |
|
| 278 |
if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) {
|
| 279 |
results.multiHandLandmarks.forEach((landmarks, index) => {
|
|
@@ -287,78 +255,65 @@
|
|
| 287 |
}
|
| 288 |
canvasCtx.restore();
|
| 289 |
|
| 290 |
-
//
|
| 291 |
-
|
| 292 |
-
// 1. Update Panel Biometric (Mood & Gender)
|
| 293 |
if (currentFaceLandmarks) {
|
| 294 |
let bio = analyzeFaceBiometrics(currentFaceLandmarks);
|
| 295 |
-
|
| 296 |
-
// GABUNGAN WAJAH & TANGAN: Jika senyum + pose positif
|
| 297 |
let isPositivePose = detectedPosesThisFrame.some(p => p.id === 1 || p.id === 2 || p.id === 3);
|
| 298 |
if (bio.moodText === "Senang 😊" && isPositivePose) {
|
| 299 |
-
bio.moodText = "Sangat Senang! ✨";
|
| 300 |
-
bio.moodColor = "#eab308";
|
| 301 |
}
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
moodValue.style.color = bio.moodColor;
|
| 306 |
-
|
| 307 |
-
// Update UI Gender
|
| 308 |
-
genderValue.textContent = bio.genderText;
|
| 309 |
-
genderValue.style.color = bio.genderColor;
|
| 310 |
-
|
| 311 |
-
// Animasi Box Panel
|
| 312 |
-
biometricContainer.style.borderColor = bio.moodColor;
|
| 313 |
-
biometricContainer.style.boxShadow = `0 0 15px ${bio.moodColor}80`;
|
| 314 |
} else {
|
| 315 |
moodValue.textContent = "Wajah Hilang"; moodValue.style.color = "#94a3b8";
|
| 316 |
genderValue.textContent = "Wajah Hilang"; genderValue.style.color = "#94a3b8";
|
| 317 |
biometricContainer.style.borderColor = "#334155";
|
| 318 |
}
|
| 319 |
|
| 320 |
-
//
|
| 321 |
-
|
|
|
|
|
|
|
| 322 |
let uniquePoseNames = [...new Set(detectedPosesThisFrame.map(p => p.name))];
|
| 323 |
statusPose.textContent = uniquePoseNames.join(" & ");
|
| 324 |
statusPose.style.color = detectedPosesThisFrame[0].color;
|
| 325 |
|
|
|
|
| 326 |
detectedPosesThisFrame.forEach((pose, i) => {
|
| 327 |
if (pose.id === 1 && anims[i]) {
|
| 328 |
const wrist = pose.wrist;
|
| 329 |
const leftPos = ((1 - wrist.x) * canvasElement.width) - 75;
|
| 330 |
const topPos = (wrist.y * canvasElement.height) + 30;
|
| 331 |
|
| 332 |
-
anims[i].style.
|
| 333 |
anims[i].style.left = `${leftPos}px`;
|
| 334 |
anims[i].style.top = `${topPos}px`;
|
| 335 |
anims[i].style.width = `150px`;
|
| 336 |
}
|
| 337 |
});
|
| 338 |
|
| 339 |
-
|
| 340 |
-
let
|
| 341 |
-
let newPoseId = null;
|
| 342 |
-
|
| 343 |
-
currentIds.forEach(id => {
|
| 344 |
-
if (!currentActivePoses.includes(id)) {
|
| 345 |
-
hasNewPose = true;
|
| 346 |
-
newPoseId = id;
|
| 347 |
-
}
|
| 348 |
-
});
|
| 349 |
|
| 350 |
-
if (
|
|
|
|
| 351 |
sounds.forEach(s => { s.pause(); s.currentTime = 0; });
|
| 352 |
-
const soundToPlay = sounds[
|
| 353 |
if (soundToPlay) soundToPlay.play();
|
| 354 |
}
|
| 355 |
|
| 356 |
-
|
|
|
|
|
|
|
| 357 |
} else {
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
|
|
|
|
|
|
|
|
|
| 362 |
}
|
| 363 |
}
|
| 364 |
});
|
|
@@ -366,7 +321,6 @@
|
|
| 366 |
startBtn.addEventListener('click', () => {
|
| 367 |
startBtn.style.display = 'none';
|
| 368 |
statusPose.textContent = "Menyiapkan Kamera...";
|
| 369 |
-
|
| 370 |
sounds.forEach(s => { s.play().then(() => { s.pause(); s.currentTime = 0; }).catch(()=>{}); });
|
| 371 |
|
| 372 |
const camera = new Camera(videoElement, {
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>AI Vision - v19 Smooth Performance</title>
|
| 7 |
|
| 8 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js" crossorigin="anonymous"></script>
|
| 9 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
|
|
|
|
| 69 |
height: 480px;
|
| 70 |
max-width: 90vw;
|
| 71 |
object-fit: cover;
|
| 72 |
+
transform: scaleX(-1);
|
| 73 |
}
|
| 74 |
|
| 75 |
+
/* PERBAIKAN CSS: Animasi GIF Transisi Halus (Anti-Blink) */
|
| 76 |
.pose1-anim {
|
| 77 |
position: absolute;
|
| 78 |
+
opacity: 0; /* Default tidak terlihat */
|
| 79 |
border-radius: 8px;
|
| 80 |
z-index: 10;
|
| 81 |
border: 2px solid #eab308;
|
| 82 |
box-shadow: 0 0 15px rgba(234, 179, 8, 0.8);
|
| 83 |
pointer-events: none;
|
| 84 |
+
/* Transisi opacity ditambahkan agar memudar perlahan saat AI berkedip */
|
| 85 |
+
transition: opacity 0.2s ease-in-out, left 0.1s linear, top 0.1s linear;
|
| 86 |
transform: scaleX(-1);
|
| 87 |
}
|
| 88 |
|
|
|
|
| 89 |
#biometricContainer {
|
| 90 |
position: absolute;
|
| 91 |
top: 15px;
|
|
|
|
| 103 |
.bio-label { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; margin-top: 8px; margin-bottom: 2px;}
|
| 104 |
.bio-label:first-child { margin-top: 0; }
|
| 105 |
.bio-value { font-size: 18px; font-weight: bold; color: #f8fafc; }
|
|
|
|
|
|
|
| 106 |
.divider { height: 1px; background-color: #334155; margin: 8px 0; }
|
| 107 |
</style>
|
| 108 |
</head>
|
| 109 |
<body>
|
| 110 |
|
| 111 |
+
<h2>🤖 AI Vision: Smooth Tracking</h2>
|
| 112 |
+
<p>Algoritma Debounce untuk Audio & Visual v19</p>
|
| 113 |
|
| 114 |
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 115 |
|
|
|
|
| 118 |
</div>
|
| 119 |
|
| 120 |
<div class="monitor-container">
|
|
|
|
| 121 |
<div id="biometricContainer">
|
| 122 |
<div class="bio-label">Kondisi Mood</div>
|
| 123 |
<div id="moodValue" class="bio-value">Menganalisis...</div>
|
|
|
|
| 124 |
<div class="divider"></div>
|
|
|
|
| 125 |
<div class="bio-label">Estimasi Anatomi</div>
|
| 126 |
<div id="genderValue" class="bio-value" style="color: #cbd5e1;">Memindai...</div>
|
| 127 |
</div>
|
|
|
|
| 157 |
document.getElementById('audio5')
|
| 158 |
];
|
| 159 |
|
| 160 |
+
// VARIABEL MEMORI (ANTI-LAG & ANTI-STUTTER)
|
| 161 |
+
let memoryActivePoses = [];
|
| 162 |
+
let memoryTimer = 0;
|
| 163 |
let currentFaceLandmarks = null;
|
| 164 |
|
| 165 |
+
function getDistance(p1, p2) { return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2)); }
|
|
|
|
|
|
|
| 166 |
|
|
|
|
| 167 |
function analyzeFaceBiometrics(faceLandmarks) {
|
| 168 |
+
const leftMouth = faceLandmarks[61]; const rightMouth = faceLandmarks[291];
|
| 169 |
+
const topLip = faceLandmarks[13]; const bottomLip = faceLandmarks[14];
|
| 170 |
+
const leftEye = faceLandmarks[33]; const rightEye = faceLandmarks[263];
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
const mouthWidth = getDistance(leftMouth, rightMouth);
|
| 173 |
const mouthHeight = getDistance(topLip, bottomLip);
|
|
|
|
| 180 |
if (openRatio > 0.15) { moodText = "Terkejut 😲"; moodColor = "#a855f7"; }
|
| 181 |
else if (smileRatio > 0.52) { moodText = "Senang 😊"; moodColor = "#10b981"; }
|
| 182 |
|
| 183 |
+
const leftCheek = faceLandmarks[234]; const rightCheek = faceLandmarks[454];
|
| 184 |
+
const leftJaw = faceLandmarks[132]; const rightJaw = faceLandmarks[361];
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
const cheekWidth = getDistance(leftCheek, rightCheek);
|
| 187 |
const jawWidth = getDistance(leftJaw, rightJaw);
|
|
|
|
|
|
|
|
|
|
| 188 |
const jawToCheekRatio = jawWidth / cheekWidth;
|
| 189 |
|
| 190 |
let genderText = "Memindai..."; let genderColor = "#cbd5e1";
|
| 191 |
+
if (jawToCheekRatio > 0.755) { genderText = "Pria 👨"; genderColor = "#60a5fa"; }
|
| 192 |
+
else { genderText = "Wanita 👩"; genderColor = "#f472b6"; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
return { moodText, moodColor, genderText, genderColor };
|
| 195 |
}
|
|
|
|
| 212 |
return null;
|
| 213 |
}
|
| 214 |
|
| 215 |
+
const faceMesh = new FaceMesh({locateFile: (file) => { return `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${file}`; }});
|
|
|
|
|
|
|
|
|
|
| 216 |
faceMesh.setOptions({ maxNumFaces: 1, refineLandmarks: true, minDetectionConfidence: 0.7, minTrackingConfidence: 0.7 });
|
| 217 |
|
| 218 |
faceMesh.onResults((results) => {
|
| 219 |
+
currentFaceLandmarks = (results.multiFaceLandmarks && results.multiFaceLandmarks.length > 0) ? results.multiFaceLandmarks[0] : null;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
});
|
| 221 |
|
| 222 |
+
const hands = new Hands({locateFile: (file) => { return `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`; }});
|
| 223 |
+
|
| 224 |
+
// PERBAIKAN PERFORMA: modelComplexity diturunkan ke 0 agar 3x lebih cepat memproses 2 tangan sekaligus
|
| 225 |
+
hands.setOptions({ maxNumHands: 2, modelComplexity: 0, minDetectionConfidence: 0.7, minTrackingConfidence: 0.7 });
|
|
|
|
| 226 |
|
| 227 |
hands.onResults((results) => {
|
| 228 |
canvasCtx.save();
|
| 229 |
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
| 230 |
canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height);
|
| 231 |
|
|
|
|
| 232 |
if (currentFaceLandmarks) {
|
| 233 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_TESSELATION, {color: '#06b6d4', lineWidth: 0.5});
|
| 234 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYE, {color: '#ec4899', lineWidth: 2});
|
|
|
|
| 239 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LIPS, {color: '#ec4899', lineWidth: 2});
|
| 240 |
}
|
| 241 |
|
|
|
|
| 242 |
let detectedPosesThisFrame = [];
|
| 243 |
+
// Reset opacity GIF (bukan display none, agar tidak kaku)
|
| 244 |
+
anims.forEach(a => a.style.opacity = '0');
|
| 245 |
|
| 246 |
if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) {
|
| 247 |
results.multiHandLandmarks.forEach((landmarks, index) => {
|
|
|
|
| 255 |
}
|
| 256 |
canvasCtx.restore();
|
| 257 |
|
| 258 |
+
// RENDER UI & LOGIKA
|
|
|
|
|
|
|
| 259 |
if (currentFaceLandmarks) {
|
| 260 |
let bio = analyzeFaceBiometrics(currentFaceLandmarks);
|
|
|
|
|
|
|
| 261 |
let isPositivePose = detectedPosesThisFrame.some(p => p.id === 1 || p.id === 2 || p.id === 3);
|
| 262 |
if (bio.moodText === "Senang 😊" && isPositivePose) {
|
| 263 |
+
bio.moodText = "Sangat Senang! ✨"; bio.moodColor = "#eab308";
|
|
|
|
| 264 |
}
|
| 265 |
+
moodValue.textContent = bio.moodText; moodValue.style.color = bio.moodColor;
|
| 266 |
+
genderValue.textContent = bio.genderText; genderValue.style.color = bio.genderColor;
|
| 267 |
+
biometricContainer.style.borderColor = bio.moodColor; biometricContainer.style.boxShadow = `0 0 15px ${bio.moodColor}80`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
} else {
|
| 269 |
moodValue.textContent = "Wajah Hilang"; moodValue.style.color = "#94a3b8";
|
| 270 |
genderValue.textContent = "Wajah Hilang"; genderValue.style.color = "#94a3b8";
|
| 271 |
biometricContainer.style.borderColor = "#334155";
|
| 272 |
}
|
| 273 |
|
| 274 |
+
// --- LOGIKA AUDIO DENGAN MEMORI DEBOUNCE ---
|
| 275 |
+
let currentIds = detectedPosesThisFrame.map(p => p.id);
|
| 276 |
+
|
| 277 |
+
if (currentIds.length > 0) {
|
| 278 |
let uniquePoseNames = [...new Set(detectedPosesThisFrame.map(p => p.name))];
|
| 279 |
statusPose.textContent = uniquePoseNames.join(" & ");
|
| 280 |
statusPose.style.color = detectedPosesThisFrame[0].color;
|
| 281 |
|
| 282 |
+
// Perbarui posisi GIF dengan halus
|
| 283 |
detectedPosesThisFrame.forEach((pose, i) => {
|
| 284 |
if (pose.id === 1 && anims[i]) {
|
| 285 |
const wrist = pose.wrist;
|
| 286 |
const leftPos = ((1 - wrist.x) * canvasElement.width) - 75;
|
| 287 |
const topPos = (wrist.y * canvasElement.height) + 30;
|
| 288 |
|
| 289 |
+
anims[i].style.opacity = '1'; // Munculkan dengan efek fade
|
| 290 |
anims[i].style.left = `${leftPos}px`;
|
| 291 |
anims[i].style.top = `${topPos}px`;
|
| 292 |
anims[i].style.width = `150px`;
|
| 293 |
}
|
| 294 |
});
|
| 295 |
|
| 296 |
+
// Cek pose baru yang belum ada di memori stabil
|
| 297 |
+
let newPoses = currentIds.filter(id => !memoryActivePoses.includes(id));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
|
| 299 |
+
if (newPoses.length > 0) {
|
| 300 |
+
let primaryNewPoseId = newPoses[0];
|
| 301 |
sounds.forEach(s => { s.pause(); s.currentTime = 0; });
|
| 302 |
+
const soundToPlay = sounds[primaryNewPoseId - 1];
|
| 303 |
if (soundToPlay) soundToPlay.play();
|
| 304 |
}
|
| 305 |
|
| 306 |
+
memoryActivePoses = currentIds; // Simpan memori terbaru
|
| 307 |
+
memoryTimer = Date.now(); // Reset stopwatch memori
|
| 308 |
+
|
| 309 |
} else {
|
| 310 |
+
// Tangan tidak terdeteksi. Jangan langsung bersihkan memori! Tunggu 0.5 detik (500ms)
|
| 311 |
+
if (Date.now() - memoryTimer > 500) {
|
| 312 |
+
if (memoryActivePoses.length > 0) {
|
| 313 |
+
statusPose.textContent = "Menunggu formasi jari...";
|
| 314 |
+
statusPose.style.color = "#94a3b8";
|
| 315 |
+
memoryActivePoses = [];
|
| 316 |
+
}
|
| 317 |
}
|
| 318 |
}
|
| 319 |
});
|
|
|
|
| 321 |
startBtn.addEventListener('click', () => {
|
| 322 |
startBtn.style.display = 'none';
|
| 323 |
statusPose.textContent = "Menyiapkan Kamera...";
|
|
|
|
| 324 |
sounds.forEach(s => { s.play().then(() => { s.pause(); s.currentTime = 0; }).catch(()=>{}); });
|
| 325 |
|
| 326 |
const camera = new Camera(videoElement, {
|