-
Notifications
You must be signed in to change notification settings - Fork 0
/
bone.js
35 lines (28 loc) · 956 Bytes
/
bone.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
function Bone(color, x, y, ang, length, id = null){
this.color = color;
this.pos1 = createVector(x, y);
this.ang = ang;
this.length = length;
this.pos2 = createVector(x+this.length*cos(this.ang), y-this.length*sin(this.ang));
this.id = id;
}
Bone.prototype.fix = function(bone){
this.fixed = bone;
}
Bone.prototype.update = function(){
if(this.fixed) this.pos1 = this.fixed.pos2;
this.pos2 = createVector(this.pos1.x+this.length*cos(this.ang), this.pos1.y-this.length*sin(this.ang));
}
Bone.prototype.setAngle = function(ang){
this.ang = ang;
}
Bone.prototype.draw = function(){
fill(this.color);
stroke(this.color);
strokeWeight(3)
ellipse(this.pos1.x, this.pos1.y, 5);
ellipse(this.pos2.x, this.pos2.y, 5);
line(this.pos1.x, this.pos1.y, this.pos2.x, this.pos2.y)
strokeWeight(0)
if(this.id) text(this.id,(this.pos1.x+this.pos2.x)/2+10, (this.pos1.y+this.pos2.y)/2+10);
}