|
35 | 35 | transform: scale(1.1); |
36 | 36 | transition: transform 0.2s, filter 0.2s; |
37 | 37 | } |
| 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 | + } |
38 | 50 | </style> |
39 | 51 | </head> |
40 | 52 | <body> |
41 | 53 | <video id="webcam" autoplay muted playsinline></video> |
42 | 54 | <canvas id="canvas"></canvas> |
43 | 55 | <div id="three-canvas"></div> |
44 | 56 | <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> |
45 | 63 |
|
46 | 64 | <script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js"></script> |
47 | 65 | <script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js"></script> |
|
127 | 145 |
|
128 | 146 | const isPinch = (landmarks) => { |
129 | 147 | 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; |
131 | 149 | }; |
132 | 150 |
|
133 | 151 | const areIndexFingersClose = (l, r) => { |
134 | 152 | const d = (a, b) => Math.hypot(a.x - b.x, a.y - b.y); |
135 | 153 | return d(l[8], r[8]) < 0.12; |
136 | 154 | }; |
137 | 155 |
|
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 | | - |
143 | 156 | const findNearestShape = (position) => { |
144 | 157 | let minDist = Infinity; |
145 | 158 | let closest = null; |
|
230 | 243 | const indexTip = landmarks[8]; |
231 | 244 | const position = get3DCoords(indexTip.x, indexTip.y); |
232 | 245 |
|
233 | | - if (isFist(landmarks)) { |
| 246 | + if (isPinch(landmarks)) { |
234 | 247 | if (!selectedShape) { |
235 | 248 | selectedShape = findNearestShape(position); |
236 | 249 | } |
|
0 commit comments