-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawLimb.js
65 lines (59 loc) · 1.63 KB
/
drawLimb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { COLOR } from "../assets/constants";
import { getCos, getSin } from "./math";
export default function drawLimb(
hand,
foreArm,
upperArm,
shoulder,
limbWidth,
limbLength,
flagX,
flagY,
upperArmAngle,
foreArmAngle
) {
const upperArmDxy = {
dx: limbLength * getCos(upperArmAngle) * flagX,
dy: -limbLength * getSin(upperArmAngle) * flagY,
};
const foreArmDxy = {
dx: -limbLength * getCos(foreArmAngle) * flagX,
dy: -limbLength * getSin(foreArmAngle) * flagY,
};
upperArm.position.set(shoulder.x + flagX * flagY, shoulder.y);
upperArm
.clear()
.lineStyle(limbWidth + 5, COLOR.DARK_SKIN)
.lineTo(upperArmDxy.dx, upperArmDxy.dy)
.moveTo(0, 0);
if (flagY === -1) {
upperArm
.lineStyle(limbWidth + 13, COLOR.PANTS)
.lineTo(upperArmDxy.dx / 2, upperArmDxy.dy / 2);
} else {
upperArm
.lineStyle(1, COLOR.DARK_SKIN)
.beginFill(COLOR.SKIN)
.drawCircle(0, 0, limbWidth / 2 + 3);
}
upperArm
.lineStyle(1, COLOR.DARK_SKIN)
.beginFill(COLOR.SKIN)
.drawCircle(upperArmDxy.dx, upperArmDxy.dy, (limbWidth + 3) / 2)
.lineStyle(limbWidth + 3, COLOR.SKIN)
.lineTo(upperArmDxy.dx, upperArmDxy.dy);
foreArm.position.set(
upperArm.x + upperArmDxy.dx,
upperArm.y + upperArmDxy.dy
);
foreArm
.clear()
.beginFill(COLOR.SKIN)
.drawCircle(0, 0, limbWidth / 2)
.lineStyle(limbWidth + 2, COLOR.DARK_SKIN)
.lineTo(foreArmDxy.dx, foreArmDxy.dy)
.moveTo(0, 0)
.lineStyle(limbWidth, COLOR.SKIN)
.lineTo(foreArmDxy.dx, foreArmDxy.dy);
hand.position.set(foreArm.x + foreArmDxy.dx, foreArm.y + foreArmDxy.dy);
}