Skip to content

Commit b21994f

Browse files
committed
add text labels beside hands
1 parent f0b472c commit b21994f

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

main.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,29 @@ function onResults(results) {
638638
if (landmarks) {
639639
drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, { color: color, lineWidth: 2 });
640640
drawLandmarks(canvasCtx, landmarks, { color: dotColor, lineWidth: 1, radius: 3 });
641+
642+
// --- Draw hand function label ---
643+
const wrist = landmarks[0]; // Use wrist as reference point
644+
const labelText = isLeft ? "Zoom" : "Rotate";
645+
646+
// Position label near but slightly offset from the wrist
647+
const labelX = wrist.x * canvasElement.width - (isLeft ? -30 : 30);
648+
const labelY = wrist.y * canvasElement.height - 25;
649+
650+
// Draw text with shadow for better visibility
651+
canvasCtx.save(); // Save the current state
652+
653+
// Apply counter-transformation to make text readable (flip horizontally)
654+
canvasCtx.scale(-1, 1);
655+
const flippedX = -labelX; // Negate x position for proper placement after flip
656+
657+
canvasCtx.font = "32px 'Courier New', monospace";
658+
canvasCtx.fillStyle = "rgba(0, 0, 0, 1.0)"; // Shadow
659+
canvasCtx.fillText(labelText, flippedX + 2, labelY + 2);
660+
canvasCtx.fillStyle = "white"; // White text
661+
canvasCtx.fillText(labelText, flippedX, labelY);
662+
663+
canvasCtx.restore(); // Restore the previous state
641664
}
642665
}
643666

@@ -797,7 +820,7 @@ function setupBloom() {
797820
// Add the UnrealBloomPass with nice default values for particles
798821
const bloomPass = new THREE.UnrealBloomPass(
799822
new THREE.Vector2(window.innerWidth, window.innerHeight), // resolution
800-
1.5, // strength (intensity of the bloom)
823+
1.3, // strength (intensity of the bloom)
801824
0.1, // radius (how far the bloom extends)
802825
0.1, // threshold (minimum brightness to apply bloom)
803826
);

styles.css

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
#patternName {
3838
position: fixed;
3939
top: 25px;
40-
left: 50%;
41-
transform: translateX(-50%);
40+
left: 25px;
41+
/* transform: translateX(-50%); */
4242
color: white;
4343
font-family: 'Courier New', Courier, monospace;
44-
font-size: 32px;
44+
font-size: 30px;
4545
pointer-events: none;
46-
z-index: 100;
46+
z-index: 103;
4747
opacity: 0;
4848
transition: opacity 0.5s ease;
4949
text-align: center;
@@ -75,8 +75,8 @@
7575
position: fixed;
7676
top: 10px;
7777
left: 32%;
78-
width: 240px; /* Smaller size */
79-
height: 135px; /* Maintain 16:9 ratio */
78+
width: 256px; /* Smaller size */
79+
height: 144px; /* Maintain 16:9 ratio */
8080
border: 1px solid white;
8181
z-index: 101; /* Ensure it's above the main canvas slightly */
8282
transform: scaleX(-1); /* Mirror flip */
@@ -87,8 +87,8 @@
8787
position: fixed;
8888
top: 10px;
8989
left: 32%;
90-
width: 240px;
91-
height: 135px;
90+
width: 256px; /* Smaller size */
91+
height: 144px; /* Maintain 16:9 ratio */
9292
z-index: 102; /* Above video */
9393
pointer-events: none; /* Allow clicks to go through */
9494
transform: scaleX(-1); /* Mirror flip to match video */

0 commit comments

Comments
 (0)