Skip to content

Commit 67a0825

Browse files
committed
add instructions
1 parent e8a809c commit 67a0825

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

index.html

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,31 @@
3535
transform: scale(1.1);
3636
transition: transform 0.2s, filter 0.2s;
3737
}
38+
#instructions {
39+
position: absolute;
40+
top: 5px;
41+
left: 5px;
42+
color: white;
43+
background: rgba(0, 0, 0, 0.5);
44+
padding: 10px 15px;
45+
/* border-radius: 10px; */
46+
font-family: sans-serif;
47+
font-size: 14px;
48+
z-index: 30;
49+
}
3850
</style>
3951
</head>
4052
<body>
4153
<video id="webcam" autoplay muted playsinline></video>
4254
<canvas id="canvas"></canvas>
4355
<div id="three-canvas"></div>
4456
<img id="recycle-bin" src="recyclebin.png" alt="Recycle Bin" />
57+
<div id="instructions">
58+
Bring hands close and pinch to create a shape<br>
59+
Move hands apart (while pinching) to make the shape larger<br>
60+
Hover over a shape and pinch to move it<br>
61+
Move a shape into the recycle bin to delete it
62+
</div>
4563

4664
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js"></script>
4765
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js"></script>
@@ -127,19 +145,14 @@
127145

128146
const isPinch = (landmarks) => {
129147
const d = (a, b) => Math.hypot(a.x - b.x, a.y - b.y, a.z - b.z);
130-
return d(landmarks[4], landmarks[8]) < 0.07;
148+
return d(landmarks[4], landmarks[8]) < 0.06;
131149
};
132150

133151
const areIndexFingersClose = (l, r) => {
134152
const d = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
135153
return d(l[8], r[8]) < 0.12;
136154
};
137155

138-
const isFist = (landmarks) => {
139-
const d = (a, b) => Math.hypot(a.x - b.x, a.y - b.y, a.z - b.z);
140-
return d(landmarks[4], landmarks[8]) < 0.05 && d(landmarks[4], landmarks[12]) < 0.07;
141-
};
142-
143156
const findNearestShape = (position) => {
144157
let minDist = Infinity;
145158
let closest = null;
@@ -230,7 +243,7 @@
230243
const indexTip = landmarks[8];
231244
const position = get3DCoords(indexTip.x, indexTip.y);
232245

233-
if (isFist(landmarks)) {
246+
if (isPinch(landmarks)) {
234247
if (!selectedShape) {
235248
selectedShape = findNearestShape(position);
236249
}

0 commit comments

Comments
 (0)