Update index.html
Browse files- index.html +160 -145
index.html
CHANGED
|
@@ -3,102 +3,107 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>
|
| 7 |
|
| 8 |
<!-- Library MediaPipe Hands -->
|
| 9 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
|
| 10 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script>
|
| 11 |
|
| 12 |
<style>
|
| 13 |
-
/*
|
| 14 |
body {
|
| 15 |
-
|
|
|
|
| 16 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 17 |
display: flex; flex-direction: column; align-items: center;
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
/* Gambar Latar Belakang Kamar Tidur */
|
| 21 |
-
background-image: url('https://images.unsplash.com/photo-1615873968403-89e068629265?q=80&w=2000&auto=format&fit=crop');
|
| 22 |
-
background-size: cover;
|
| 23 |
-
background-position: center;
|
| 24 |
-
background-attachment: fixed;
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
/* OVERLAY GELAP/TERANG UNTUK EFEK RUANGAN */
|
| 28 |
-
.room-overlay {
|
| 29 |
-
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
|
| 30 |
-
background-color: rgba(2, 6, 23, 0.92); /* Sangat gelap saat lampu mati */
|
| 31 |
-
transition: background-color 0.6s ease-in-out;
|
| 32 |
-
z-index: 0;
|
| 33 |
-
}
|
| 34 |
-
/* Saat lampu hidup, ruangan sedikit diterangi */
|
| 35 |
-
body.lamp-is-on .room-overlay {
|
| 36 |
-
background-color: rgba(2, 6, 23, 0.5);
|
| 37 |
}
|
| 38 |
-
|
| 39 |
-
/*
|
| 40 |
-
.
|
| 41 |
-
|
| 42 |
-
display: flex; flex-direction: column; align-items: center; width: 100%;
|
| 43 |
}
|
| 44 |
|
| 45 |
h2 {
|
| 46 |
margin-bottom: 5px; color: #38bdf8;
|
| 47 |
-
font-weight:
|
| 48 |
-
text-shadow: 0 0
|
| 49 |
}
|
| 50 |
-
p { color: #cbd5e1; margin-top: 0; text-align: center; font-weight: 500; font-size:
|
| 51 |
|
|
|
|
| 52 |
#startBtn {
|
| 53 |
-
background: linear-gradient(135deg, #
|
| 54 |
color: white; border: none; padding: 12px 35px;
|
| 55 |
-
font-size:
|
| 56 |
-
font-weight: bold; box-shadow: 0
|
| 57 |
transition: all 0.3s ease; margin: 15px 0; text-transform: uppercase;
|
|
|
|
| 58 |
}
|
| 59 |
-
#startBtn:hover { transform: translateY(-2px); box-shadow: 0
|
| 60 |
|
| 61 |
-
/*
|
| 62 |
#statusContainer {
|
| 63 |
-
background: rgba(15, 23, 42, 0.
|
| 64 |
-
padding: 10px 30px; border-radius: 12px; margin-bottom:
|
| 65 |
-
text-align: center;
|
| 66 |
-
box-shadow: 0 10px 25px rgba(0,0,0,0.5);
|
| 67 |
}
|
| 68 |
-
#statusPose { font-size:
|
| 69 |
|
| 70 |
-
/* --- VISUALISASI LAMPU TIDUR
|
| 71 |
.lamp-container {
|
| 72 |
-
margin-bottom:
|
| 73 |
filter: drop-shadow(0 15px 15px rgba(0,0,0,0.5));
|
| 74 |
}
|
| 75 |
|
| 76 |
#nightLampSvg {
|
| 77 |
-
width:
|
| 78 |
-
overflow: visible;
|
| 79 |
transition: all 0.5s ease-in-out;
|
| 80 |
}
|
| 81 |
|
| 82 |
/* Komponen Lampu */
|
| 83 |
-
.lamp-glow { fill: rgba(253, 224, 71, 0); filter: blur(
|
| 84 |
.lamp-shade { fill: #f8fafc; transition: fill 0.5s ease; }
|
| 85 |
.lamp-stand { fill: #64748b; }
|
| 86 |
.lamp-base { fill: #334155; }
|
| 87 |
|
| 88 |
-
/*
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
| 91 |
}
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
}
|
| 95 |
|
| 96 |
-
/* MONITOR KAMERA */
|
| 97 |
.canvas-container {
|
| 98 |
position: relative;
|
| 99 |
width: 480px; height: 360px;
|
| 100 |
-
border: 3px solid rgba(255,255,255,0.2);
|
| 101 |
-
box-shadow: 0 20px 40px rgba(0,0,0,0.8);
|
| 102 |
border-radius: 16px; overflow: hidden;
|
| 103 |
background-color: #000;
|
| 104 |
}
|
|
@@ -119,43 +124,42 @@
|
|
| 119 |
</head>
|
| 120 |
<body>
|
| 121 |
|
| 122 |
-
<
|
| 123 |
-
<
|
| 124 |
-
|
| 125 |
-
<
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
<
|
| 130 |
-
|
| 131 |
-
<!-- TAMPILAN STATUS -->
|
| 132 |
-
<div id="statusContainer">
|
| 133 |
-
<div id="statusPose">Menunggu Kamera...</div>
|
| 134 |
-
</div>
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
| 153 |
<circle cx="75" cy="87" r="3" fill="#cbd5e1" />
|
| 154 |
-
</
|
| 155 |
-
</
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
| 157 |
<div class="canvas-container">
|
| 158 |
-
<!-- Kamera langsung muncul -->
|
| 159 |
<video id="videoElement" autoplay playsinline webkit-playsinline muted></video>
|
| 160 |
<canvas id="outputCanvas" width="480" height="360"></canvas>
|
| 161 |
</div>
|
|
@@ -167,109 +171,120 @@
|
|
| 167 |
const canvasCtx = canvasElement.getContext('2d');
|
| 168 |
const startBtn = document.getElementById('startBtn');
|
| 169 |
const statusPose = document.getElementById('statusPose');
|
|
|
|
|
|
|
| 170 |
|
| 171 |
-
// Status awal: Lampu Mati
|
| 172 |
let isLampOn = false;
|
| 173 |
|
| 174 |
-
// --- LOGIKA DETEKSI
|
| 175 |
function analyzePoses(multiHandLandmarks) {
|
| 176 |
if (!multiHandLandmarks || multiHandLandmarks.length === 0) return null;
|
| 177 |
|
| 178 |
-
// Ambil tangan pertama
|
| 179 |
const lm = multiHandLandmarks[0];
|
| 180 |
|
| 181 |
-
// Cek kondisi jari berdiri
|
| 182 |
const indexUp = lm[8].y < lm[6].y;
|
| 183 |
const middleUp = lm[12].y < lm[10].y;
|
| 184 |
const ringUp = lm[16].y < lm[14].y;
|
| 185 |
const pinkyUp = lm[20].y < lm[18].y;
|
| 186 |
|
| 187 |
-
// Jumlah jari berdiri
|
| 188 |
const fingersUpCount = [indexUp, middleUp, ringUp, pinkyUp].filter(Boolean).length;
|
| 189 |
|
| 190 |
-
// ποΈ
|
| 191 |
-
if (fingersUpCount >= 3) {
|
| 192 |
-
return 'palm';
|
| 193 |
-
}
|
| 194 |
|
| 195 |
-
// βοΈ
|
| 196 |
-
if (indexUp && middleUp && !ringUp && !pinkyUp) {
|
| 197 |
-
return 'victory';
|
| 198 |
-
}
|
| 199 |
|
| 200 |
-
return null;
|
| 201 |
}
|
| 202 |
|
| 203 |
-
// ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
const hands = new Hands({locateFile: (file) => `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`});
|
| 205 |
-
|
| 206 |
hands.setOptions({
|
| 207 |
maxNumHands: 1,
|
| 208 |
modelComplexity: 0,
|
| 209 |
-
minDetectionConfidence: 0.
|
| 210 |
-
minTrackingConfidence: 0.
|
| 211 |
});
|
| 212 |
|
| 213 |
hands.onResults((results) => {
|
| 214 |
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
| 215 |
|
| 216 |
-
// Render Tulang Tangan (Warna Kuning agar senada dengan cahaya)
|
| 217 |
-
if (results.multiHandLandmarks) {
|
| 218 |
-
results.multiHandLandmarks.forEach((landmarks) => {
|
| 219 |
-
drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {color: '#facc15', lineWidth: 3});
|
| 220 |
-
drawLandmarks(canvasCtx, landmarks, {color: '#ffffff', lineWidth: 1, radius: 2});
|
| 221 |
-
});
|
| 222 |
-
}
|
| 223 |
-
|
| 224 |
const detectedPose = analyzePoses(results.multiHandLandmarks);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
-
//
|
|
|
|
|
|
|
| 227 |
if (detectedPose === 'palm') {
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
statusPose.textContent = "π‘ Pose: ποΈ Lampu Menyala";
|
| 234 |
-
statusPose.style.color = "#fef08a"; // Kuning Terang
|
| 235 |
-
}
|
| 236 |
}
|
| 237 |
else if (detectedPose === 'victory') {
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
}
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
statusPose.style.color = "#94a3b8";
|
| 256 |
}
|
| 257 |
});
|
| 258 |
|
| 259 |
-
// --- SISTEM KAMERA
|
| 260 |
startBtn.addEventListener('click', async () => {
|
| 261 |
startBtn.style.display = 'none';
|
| 262 |
statusPose.textContent = "Meminta Izin Kamera...";
|
| 263 |
|
| 264 |
try {
|
| 265 |
-
const stream = await navigator.mediaDevices.getUserMedia({
|
| 266 |
-
video: { width: 480, height: 360 }
|
| 267 |
-
});
|
| 268 |
videoElement.srcObject = stream;
|
| 269 |
|
| 270 |
videoElement.onloadedmetadata = () => {
|
| 271 |
videoElement.play();
|
| 272 |
-
statusPose.textContent = "
|
| 273 |
statusPose.style.color = "#f8fafc";
|
| 274 |
|
| 275 |
async function processFrame() {
|
|
@@ -281,11 +296,11 @@
|
|
| 281 |
processFrame();
|
| 282 |
};
|
| 283 |
} catch (error) {
|
| 284 |
-
alert("GAGAL AKSES KAMERA!\nPastikan Anda klik 'Allow/Izinkan'.\n\nError: " + error.message);
|
| 285 |
statusPose.textContent = "Kamera Terblokir π΄";
|
| 286 |
startBtn.style.display = 'block';
|
| 287 |
}
|
| 288 |
});
|
| 289 |
</script>
|
| 290 |
</body>
|
| 291 |
-
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Smart Night Lamp AI</title>
|
| 7 |
|
| 8 |
<!-- Library MediaPipe Hands -->
|
| 9 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
|
| 10 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script>
|
| 11 |
|
| 12 |
<style>
|
| 13 |
+
/* TEMA GELAP BERSIH SESUAI GAMBAR */
|
| 14 |
body {
|
| 15 |
+
background: #0f172a; /* Warna dark blue pekat */
|
| 16 |
+
color: #f8fafc;
|
| 17 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 18 |
display: flex; flex-direction: column; align-items: center;
|
| 19 |
+
margin: 0; padding: 30px 20px; min-height: 100vh; overflow-x: hidden;
|
| 20 |
+
transition: background-color 0.5s ease;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
+
|
| 23 |
+
/* Jika lampu hidup, background sedikit lebih terang (glow effect) */
|
| 24 |
+
body.lamp-is-on {
|
| 25 |
+
background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
|
|
|
|
| 26 |
}
|
| 27 |
|
| 28 |
h2 {
|
| 29 |
margin-bottom: 5px; color: #38bdf8;
|
| 30 |
+
font-weight: 900; font-size: 24px; text-transform: uppercase; letter-spacing: 1px;
|
| 31 |
+
text-shadow: 0 0 15px rgba(56, 189, 248, 0.6);
|
| 32 |
}
|
| 33 |
+
p { color: #cbd5e1; margin-top: 0; text-align: center; font-weight: 500; font-size: 14px;}
|
| 34 |
|
| 35 |
+
/* TOMBOL AKTIFKAN */
|
| 36 |
#startBtn {
|
| 37 |
+
background: linear-gradient(135deg, #d946ef, #a855f7);
|
| 38 |
color: white; border: none; padding: 12px 35px;
|
| 39 |
+
font-size: 14px; border-radius: 50px; cursor: pointer;
|
| 40 |
+
font-weight: bold; box-shadow: 0 0 20px rgba(217, 70, 239, 0.5);
|
| 41 |
transition: all 0.3s ease; margin: 15px 0; text-transform: uppercase;
|
| 42 |
+
letter-spacing: 1px;
|
| 43 |
}
|
| 44 |
+
#startBtn:hover { transform: translateY(-2px); box-shadow: 0 0 30px rgba(217, 70, 239, 0.8); }
|
| 45 |
|
| 46 |
+
/* STATUS BOX */
|
| 47 |
#statusContainer {
|
| 48 |
+
background: rgba(15, 23, 42, 0.8); border: 1px solid #334155;
|
| 49 |
+
padding: 10px 30px; border-radius: 12px; margin-bottom: 30px;
|
| 50 |
+
text-align: center; box-shadow: 0 4px 6px rgba(0,0,0,0.3);
|
|
|
|
| 51 |
}
|
| 52 |
+
#statusPose { font-size: 16px; font-weight: bold; color: #f8fafc; transition: color 0.3s;}
|
| 53 |
|
| 54 |
+
/* --- VISUALISASI LAMPU TIDUR --- */
|
| 55 |
.lamp-container {
|
| 56 |
+
margin-bottom: 30px;
|
| 57 |
filter: drop-shadow(0 15px 15px rgba(0,0,0,0.5));
|
| 58 |
}
|
| 59 |
|
| 60 |
#nightLampSvg {
|
| 61 |
+
width: 120px; height: 140px;
|
| 62 |
+
overflow: visible;
|
| 63 |
transition: all 0.5s ease-in-out;
|
| 64 |
}
|
| 65 |
|
| 66 |
/* Komponen Lampu */
|
| 67 |
+
.lamp-glow { fill: rgba(253, 224, 71, 0); filter: blur(20px); transition: fill 0.5s ease; }
|
| 68 |
.lamp-shade { fill: #f8fafc; transition: fill 0.5s ease; }
|
| 69 |
.lamp-stand { fill: #64748b; }
|
| 70 |
.lamp-base { fill: #334155; }
|
| 71 |
|
| 72 |
+
/* Animasi Tarik Tali */
|
| 73 |
+
@keyframes pullDown {
|
| 74 |
+
0% { transform: translateY(0); }
|
| 75 |
+
50% { transform: translateY(12px); } /* Tali turun 12px */
|
| 76 |
+
100% { transform: translateY(0); }
|
| 77 |
}
|
| 78 |
+
.pull-active {
|
| 79 |
+
animation: pullDown 0.4s ease-in-out;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
/* Efek Saat Lampu Hidup */
|
| 83 |
+
body.lamp-is-on .lamp-glow { fill: rgba(253, 224, 71, 0.7); }
|
| 84 |
+
body.lamp-is-on .lamp-shade { fill: #fef08a; }
|
| 85 |
+
|
| 86 |
+
/* --- MONITOR KAMERA --- */
|
| 87 |
+
.canvas-wrapper {
|
| 88 |
+
padding: 4px;
|
| 89 |
+
border-radius: 20px;
|
| 90 |
+
background: #334155; /* Border abu-abu default */
|
| 91 |
+
transition: background 0.3s ease, box-shadow 0.3s ease;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/* Efek Frame Kamera Menyala sesuai Gerakan */
|
| 95 |
+
.canvas-wrapper.glow-yellow {
|
| 96 |
+
background: linear-gradient(135deg, #facc15, #f59e0b);
|
| 97 |
+
box-shadow: 0 0 30px rgba(250, 204, 21, 0.5);
|
| 98 |
+
}
|
| 99 |
+
.canvas-wrapper.glow-pink {
|
| 100 |
+
background: linear-gradient(135deg, #f472b6, #db2777);
|
| 101 |
+
box-shadow: 0 0 30px rgba(244, 114, 182, 0.5);
|
| 102 |
}
|
| 103 |
|
|
|
|
| 104 |
.canvas-container {
|
| 105 |
position: relative;
|
| 106 |
width: 480px; height: 360px;
|
|
|
|
|
|
|
| 107 |
border-radius: 16px; overflow: hidden;
|
| 108 |
background-color: #000;
|
| 109 |
}
|
|
|
|
| 124 |
</head>
|
| 125 |
<body>
|
| 126 |
|
| 127 |
+
<h2>β‘ SMART NIGHT LAMP</h2>
|
| 128 |
+
<p>ποΈ Buka Telapak (Hidupkan) | βοΈ Pose Peace (Matikan)</p>
|
| 129 |
+
|
| 130 |
+
<button id="startBtn">βΆ AKTIFKAN AI KAMERA</button>
|
| 131 |
+
|
| 132 |
+
<!-- Status -->
|
| 133 |
+
<div id="statusContainer">
|
| 134 |
+
<div id="statusPose">Menunggu Kamera...</div>
|
| 135 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
+
<!-- Visualisasi Lampu SVG -->
|
| 138 |
+
<div class="lamp-container">
|
| 139 |
+
<svg id="nightLampSvg" viewBox="0 0 100 120" xmlns="http://www.w3.org/2000/svg">
|
| 140 |
+
<!-- Lingkaran Cahaya Glow -->
|
| 141 |
+
<circle class="lamp-glow" cx="50" cy="50" r="45" />
|
| 142 |
+
|
| 143 |
+
<!-- Kap Lampu -->
|
| 144 |
+
<polygon class="lamp-shade" points="30,20 70,20 85,65 15,65" />
|
| 145 |
+
|
| 146 |
+
<!-- Tiang -->
|
| 147 |
+
<rect class="lamp-stand" x="46" y="65" width="8" height="45" />
|
| 148 |
+
|
| 149 |
+
<!-- Tapak -->
|
| 150 |
+
<rect class="lamp-base" x="25" y="110" width="50" height="8" rx="4" />
|
| 151 |
+
|
| 152 |
+
<!-- Tali & Bandul (Di-group agar bisa dianismasikan bersamaan) -->
|
| 153 |
+
<g id="pullCordGroup">
|
| 154 |
+
<line x1="75" y1="65" x2="75" y2="85" stroke="#cbd5e1" stroke-width="2" />
|
| 155 |
<circle cx="75" cy="87" r="3" fill="#cbd5e1" />
|
| 156 |
+
</g>
|
| 157 |
+
</svg>
|
| 158 |
+
</div>
|
| 159 |
+
|
| 160 |
+
<!-- Frame Kamera -->
|
| 161 |
+
<div class="canvas-wrapper" id="canvasFrame">
|
| 162 |
<div class="canvas-container">
|
|
|
|
| 163 |
<video id="videoElement" autoplay playsinline webkit-playsinline muted></video>
|
| 164 |
<canvas id="outputCanvas" width="480" height="360"></canvas>
|
| 165 |
</div>
|
|
|
|
| 171 |
const canvasCtx = canvasElement.getContext('2d');
|
| 172 |
const startBtn = document.getElementById('startBtn');
|
| 173 |
const statusPose = document.getElementById('statusPose');
|
| 174 |
+
const pullCordGroup = document.getElementById('pullCordGroup');
|
| 175 |
+
const canvasFrame = document.getElementById('canvasFrame');
|
| 176 |
|
|
|
|
| 177 |
let isLampOn = false;
|
| 178 |
|
| 179 |
+
// --- LOGIKA DETEKSI 2 POSE ---
|
| 180 |
function analyzePoses(multiHandLandmarks) {
|
| 181 |
if (!multiHandLandmarks || multiHandLandmarks.length === 0) return null;
|
| 182 |
|
|
|
|
| 183 |
const lm = multiHandLandmarks[0];
|
| 184 |
|
| 185 |
+
// Cek kondisi ujung jari di atas buku jari (berdiri)
|
| 186 |
const indexUp = lm[8].y < lm[6].y;
|
| 187 |
const middleUp = lm[12].y < lm[10].y;
|
| 188 |
const ringUp = lm[16].y < lm[14].y;
|
| 189 |
const pinkyUp = lm[20].y < lm[18].y;
|
| 190 |
|
|
|
|
| 191 |
const fingersUpCount = [indexUp, middleUp, ringUp, pinkyUp].filter(Boolean).length;
|
| 192 |
|
| 193 |
+
// ποΈ Telapak Terbuka
|
| 194 |
+
if (fingersUpCount >= 3) { return 'palm'; }
|
|
|
|
|
|
|
| 195 |
|
| 196 |
+
// βοΈ Peace Sign
|
| 197 |
+
if (indexUp && middleUp && !ringUp && !pinkyUp) { return 'victory'; }
|
|
|
|
|
|
|
| 198 |
|
| 199 |
+
return null;
|
| 200 |
}
|
| 201 |
|
| 202 |
+
// --- FUNGSI ANIMASI TALI & LAMPU ---
|
| 203 |
+
function triggerLampToggle(turnOn) {
|
| 204 |
+
// Hapus class animasi jika masih ada, paksa reflow, lalu tambahkan lagi agar animasi terpicu berulang kali
|
| 205 |
+
pullCordGroup.classList.remove('pull-active');
|
| 206 |
+
void pullCordGroup.offsetWidth;
|
| 207 |
+
pullCordGroup.classList.add('pull-active');
|
| 208 |
+
|
| 209 |
+
if (turnOn) {
|
| 210 |
+
isLampOn = true;
|
| 211 |
+
document.body.classList.add('lamp-is-on');
|
| 212 |
+
statusPose.textContent = "π‘ LAMPU MENYALA";
|
| 213 |
+
statusPose.style.color = "#fef08a"; // Kuning
|
| 214 |
+
} else {
|
| 215 |
+
isLampOn = false;
|
| 216 |
+
document.body.classList.remove('lamp-is-on');
|
| 217 |
+
statusPose.textContent = "π LAMPU MATI";
|
| 218 |
+
statusPose.style.color = "#cbd5e1"; // Abu-abu
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
// --- SETUP AI ---
|
| 223 |
const hands = new Hands({locateFile: (file) => `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`});
|
|
|
|
| 224 |
hands.setOptions({
|
| 225 |
maxNumHands: 1,
|
| 226 |
modelComplexity: 0,
|
| 227 |
+
minDetectionConfidence: 0.6,
|
| 228 |
+
minTrackingConfidence: 0.6
|
| 229 |
});
|
| 230 |
|
| 231 |
hands.onResults((results) => {
|
| 232 |
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
| 233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
const detectedPose = analyzePoses(results.multiHandLandmarks);
|
| 235 |
+
|
| 236 |
+
// Pengaturan Visual Rangka Tangan (Efek Deteksi)
|
| 237 |
+
let skeletonColor = '#38bdf8'; // Default Biru
|
| 238 |
+
let landmarkColor = '#ffffff'; // Default Putih
|
| 239 |
|
| 240 |
+
// Reset Frame Kamera
|
| 241 |
+
canvasFrame.className = 'canvas-wrapper';
|
| 242 |
+
|
| 243 |
if (detectedPose === 'palm') {
|
| 244 |
+
skeletonColor = '#facc15'; // Berubah Kuning
|
| 245 |
+
landmarkColor = '#fef08a';
|
| 246 |
+
canvasFrame.classList.add('glow-yellow'); // Frame ikutan nyala kuning
|
| 247 |
+
|
| 248 |
+
if (!isLampOn) triggerLampToggle(true);
|
|
|
|
|
|
|
|
|
|
| 249 |
}
|
| 250 |
else if (detectedPose === 'victory') {
|
| 251 |
+
skeletonColor = '#f472b6'; // Berubah Pink
|
| 252 |
+
landmarkColor = '#fbcfe8';
|
| 253 |
+
canvasFrame.classList.add('glow-pink'); // Frame ikutan nyala pink
|
| 254 |
+
|
| 255 |
+
if (isLampOn) triggerLampToggle(false);
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
// Gambar Tulang Tangan di Atas Video
|
| 259 |
+
if (results.multiHandLandmarks) {
|
| 260 |
+
results.multiHandLandmarks.forEach((landmarks) => {
|
| 261 |
+
drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {color: skeletonColor, lineWidth: 5});
|
| 262 |
+
drawLandmarks(canvasCtx, landmarks, {color: landmarkColor, lineWidth: 2, radius: 4});
|
| 263 |
+
});
|
| 264 |
}
|
| 265 |
+
|
| 266 |
+
// Update teks jika tangan ada tapi pose acak
|
| 267 |
+
if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0 && !detectedPose) {
|
| 268 |
+
statusPose.textContent = "Arahkan Pose ποΈ atau βοΈ";
|
| 269 |
+
statusPose.style.color = "#f8fafc";
|
| 270 |
+
} else if (!results.multiHandLandmarks || results.multiHandLandmarks.length === 0) {
|
| 271 |
+
statusPose.textContent = "Kamera Aktif. Menunggu Tangan...";
|
| 272 |
statusPose.style.color = "#94a3b8";
|
| 273 |
}
|
| 274 |
});
|
| 275 |
|
| 276 |
+
// --- SISTEM KAMERA ---
|
| 277 |
startBtn.addEventListener('click', async () => {
|
| 278 |
startBtn.style.display = 'none';
|
| 279 |
statusPose.textContent = "Meminta Izin Kamera...";
|
| 280 |
|
| 281 |
try {
|
| 282 |
+
const stream = await navigator.mediaDevices.getUserMedia({ video: { width: 480, height: 360 } });
|
|
|
|
|
|
|
| 283 |
videoElement.srcObject = stream;
|
| 284 |
|
| 285 |
videoElement.onloadedmetadata = () => {
|
| 286 |
videoElement.play();
|
| 287 |
+
statusPose.textContent = "Kamera Terhubung! π";
|
| 288 |
statusPose.style.color = "#f8fafc";
|
| 289 |
|
| 290 |
async function processFrame() {
|
|
|
|
| 296 |
processFrame();
|
| 297 |
};
|
| 298 |
} catch (error) {
|
| 299 |
+
alert("GAGAL AKSES KAMERA!\nPastikan Anda klik 'Allow/Izinkan' di browser.\n\nError: " + error.message);
|
| 300 |
statusPose.textContent = "Kamera Terblokir π΄";
|
| 301 |
startBtn.style.display = 'block';
|
| 302 |
}
|
| 303 |
});
|
| 304 |
</script>
|
| 305 |
</body>
|
| 306 |
+
</html>
|