Spaces:
Sleeping
Sleeping
modify draw style
Browse files- static/poseEditor.js +13 -6
static/poseEditor.js
CHANGED
|
@@ -52,7 +52,7 @@ function resizeCanvas(width, height) {
|
|
| 52 |
}
|
| 53 |
|
| 54 |
function drawBodyPose(candidate, subset) {
|
| 55 |
-
const
|
| 56 |
const limbSeq = [[2, 3], [2, 6], [3, 4], [4, 5], [6, 7], [7, 8], [2, 9], [9, 10],
|
| 57 |
[10, 11], [2, 12], [12, 13], [13, 14], [2, 1], [1, 15], [15, 17],
|
| 58 |
[1, 16], [16, 18], [3, 17], [6, 18]];
|
|
@@ -60,7 +60,10 @@ function drawBodyPose(candidate, subset) {
|
|
| 60 |
const colors = [[255, 0, 0], [255, 85, 0], [255, 170, 0], [255, 255, 0], [170, 255, 0], [85, 255, 0], [0, 255, 0],
|
| 61 |
[0, 255, 85], [0, 255, 170], [0, 255, 255], [0, 170, 255], [0, 85, 255], [0, 0, 255], [85, 0, 255],
|
| 62 |
[170, 0, 255], [255, 0, 255], [255, 0, 170], [255, 0, 85]];
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
| 64 |
for (let i = 0; i < 17; i++) {
|
| 65 |
for (let n = 0; n < subset.length; n++) {
|
| 66 |
const index0 = subset[n][limbSeq[i][0]-1];
|
|
@@ -71,7 +74,7 @@ function drawBodyPose(candidate, subset) {
|
|
| 71 |
const [X0, Y0] = candidate[index0].slice(0, 2);
|
| 72 |
const [X1, Y1] = candidate[index1].slice(0, 2);
|
| 73 |
ctx.beginPath();
|
| 74 |
-
ctx.lineWidth=
|
| 75 |
ctx.strokeStyle = `rgb(${colors[i].join(',')})`;
|
| 76 |
ctx.moveTo(X0, Y0);
|
| 77 |
ctx.lineTo(X1, Y1);
|
|
@@ -79,6 +82,7 @@ function drawBodyPose(candidate, subset) {
|
|
| 79 |
}
|
| 80 |
}
|
| 81 |
|
|
|
|
| 82 |
ctx.font = '12px serif';
|
| 83 |
for (let i = 0; i < 18; i++) {
|
| 84 |
for (let n = 0; n < subset.length; n++) {
|
|
@@ -88,13 +92,15 @@ function drawBodyPose(candidate, subset) {
|
|
| 88 |
}
|
| 89 |
const [x, y] = candidate[index].slice(0, 2);
|
| 90 |
ctx.beginPath();
|
| 91 |
-
ctx.arc(x, y,
|
| 92 |
ctx.fillStyle = `rgb(${colors[i].join(',')})`;
|
| 93 |
ctx.fill();
|
| 94 |
ctx.fillStyle = 'rgb(255,255,255)'
|
| 95 |
// ctx.fillText(index, x-3, y+4);
|
| 96 |
}
|
| 97 |
}
|
|
|
|
|
|
|
| 98 |
}
|
| 99 |
|
| 100 |
function drawUI() {
|
|
@@ -126,6 +132,7 @@ function getNearestCandidate(x, y) {
|
|
| 126 |
}
|
| 127 |
|
| 128 |
let dragRange = 64;
|
|
|
|
| 129 |
|
| 130 |
// ドラッグ中に座標を保持するための変数
|
| 131 |
let isDragging = false;
|
|
@@ -255,8 +262,8 @@ function handleMouseMove(event) {
|
|
| 255 |
function handleMouseUp(event) { isDragging = false; }
|
| 256 |
|
| 257 |
document.addEventListener("keydown", (event) => {
|
| 258 |
-
if (event.code == "BracketLeft") {dragRange = Math.max(
|
| 259 |
-
if (event.code == "BracketRight") {dragRange = Math.min(
|
| 260 |
keyDownFlags[event.code] = true;
|
| 261 |
Redraw();
|
| 262 |
});
|
|
|
|
| 52 |
}
|
| 53 |
|
| 54 |
function drawBodyPose(candidate, subset) {
|
| 55 |
+
const stickWidth = 6;
|
| 56 |
const limbSeq = [[2, 3], [2, 6], [3, 4], [4, 5], [6, 7], [7, 8], [2, 9], [9, 10],
|
| 57 |
[10, 11], [2, 12], [12, 13], [13, 14], [2, 1], [1, 15], [15, 17],
|
| 58 |
[1, 16], [16, 18], [3, 17], [6, 18]];
|
|
|
|
| 60 |
const colors = [[255, 0, 0], [255, 85, 0], [255, 170, 0], [255, 255, 0], [170, 255, 0], [85, 255, 0], [0, 255, 0],
|
| 61 |
[0, 255, 85], [0, 255, 170], [0, 255, 255], [0, 170, 255], [0, 85, 255], [0, 0, 255], [85, 0, 255],
|
| 62 |
[170, 0, 255], [255, 0, 255], [255, 0, 170], [255, 0, 85]];
|
| 63 |
+
|
| 64 |
+
ctx.globalAlpha = 0.7;
|
| 65 |
+
|
| 66 |
+
// edge
|
| 67 |
for (let i = 0; i < 17; i++) {
|
| 68 |
for (let n = 0; n < subset.length; n++) {
|
| 69 |
const index0 = subset[n][limbSeq[i][0]-1];
|
|
|
|
| 74 |
const [X0, Y0] = candidate[index0].slice(0, 2);
|
| 75 |
const [X1, Y1] = candidate[index1].slice(0, 2);
|
| 76 |
ctx.beginPath();
|
| 77 |
+
ctx.lineWidth=stickWidth;
|
| 78 |
ctx.strokeStyle = `rgb(${colors[i].join(',')})`;
|
| 79 |
ctx.moveTo(X0, Y0);
|
| 80 |
ctx.lineTo(X1, Y1);
|
|
|
|
| 82 |
}
|
| 83 |
}
|
| 84 |
|
| 85 |
+
// node
|
| 86 |
ctx.font = '12px serif';
|
| 87 |
for (let i = 0; i < 18; i++) {
|
| 88 |
for (let n = 0; n < subset.length; n++) {
|
|
|
|
| 92 |
}
|
| 93 |
const [x, y] = candidate[index].slice(0, 2);
|
| 94 |
ctx.beginPath();
|
| 95 |
+
ctx.arc(x, y, stickWidth*1.2, 0, 2 * Math.PI);
|
| 96 |
ctx.fillStyle = `rgb(${colors[i].join(',')})`;
|
| 97 |
ctx.fill();
|
| 98 |
ctx.fillStyle = 'rgb(255,255,255)'
|
| 99 |
// ctx.fillText(index, x-3, y+4);
|
| 100 |
}
|
| 101 |
}
|
| 102 |
+
|
| 103 |
+
ctx.globalAlpha = 1.0;
|
| 104 |
}
|
| 105 |
|
| 106 |
function drawUI() {
|
|
|
|
| 132 |
}
|
| 133 |
|
| 134 |
let dragRange = 64;
|
| 135 |
+
let dragRangeDelta = 16;
|
| 136 |
|
| 137 |
// ドラッグ中に座標を保持するための変数
|
| 138 |
let isDragging = false;
|
|
|
|
| 262 |
function handleMouseUp(event) { isDragging = false; }
|
| 263 |
|
| 264 |
document.addEventListener("keydown", (event) => {
|
| 265 |
+
if (event.code == "BracketLeft") {dragRange = Math.max(dragRangeDelta, dragRange - dragRangeDelta);}
|
| 266 |
+
if (event.code == "BracketRight") {dragRange = Math.min(512, dragRange + dragRangeDelta);}
|
| 267 |
keyDownFlags[event.code] = true;
|
| 268 |
Redraw();
|
| 269 |
});
|