forked from jsoverson/JavaScript-Particle-System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathField.js
More file actions
43 lines (34 loc) · 929 Bytes
/
Copy pathField.js
File metadata and controls
43 lines (34 loc) · 929 Bytes
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
/*global define*/
define(['lib/Vector'],function(Vector){
"use strict";
function Field(point, mass) {
this.position = point;
this.size = 15;
this.mass = 0;
this.drawColor = '#b00';
this.setMass(mass);
}
Field.drawColor = "rgb(0,0,255)";
Field.drawColor2 = "hsl(0,0%,0%)";
Field.prototype.setMass = function(mass) {
this.mass = mass;
this.drawColor = mass < 0 ? "#f00" : "#0f0";
return this;
};
Field.prototype.moveTo = function(point) {
this.position = point;
};
Field.prototype.toString = function() {
var coreAttributes = [
this.position.toString(),
this.mass
];
return 'F' + coreAttributes.join(':');
};
Field.fromString = function(string) {
var parts = string.substr(1).split(':');
var field = new Field(Vector.fromString(parts.shift()),parseInt(parts.shift(),10));
return field;
};
return Field;
});