-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoint.js
44 lines (33 loc) · 912 Bytes
/
point.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
var Point = function(canvas, x, y){
this.canvas = canvas;
this.current = this.previous = new FastVector(x, y);
this.mass = this.inv_mass = 1;
this.force = new FastVector(0.0,0.5).multiply(0.05 * 0.05);
this.radius = 3;
};
Point.prototype = {
setCurrent: function(p) {
this.current = p;
},
setPrevious: function(p) {
this.previous = p;
},
getCurrent: function() {
return this.current;
},
getPrevious: function() {
return this.previous;
},
move: function() {
if (this.inv_mass!=0){
var new_pos = this.current.multiply(1.99).subtract(this.previous.multiply(0.99)).add(this.force);
new_pos.x = (new_pos.x < 0) ? 0 : ((new_pos.x > 1) ? 1 : new_pos.x);
new_pos.y = (new_pos.y < 0) ? 0 : ((new_pos.y > 1) ? 1 : new_pos.y);
this.previous = this.current;
this.current = new_pos;
}
},
draw: function() {
this.canvas.circle(this.current, this.radius);
}
};