summaryrefslogtreecommitdiffstats
path: root/attractors4/particle.js
diff options
context:
space:
mode:
Diffstat (limited to 'attractors4/particle.js')
-rw-r--r--attractors4/particle.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/attractors4/particle.js b/attractors4/particle.js
new file mode 100644
index 0000000..ac09423
--- /dev/null
+++ b/attractors4/particle.js
@@ -0,0 +1,26 @@
+( function() {
+
+function Particle( x, y ) {
+ this.x = x;
+ this.y = y;
+ this.velocity = 0;
+ this.accel = 0;
+}
+
+var friction = 0.3;
+
+
+Particle.prototype.update = function() {
+ this.velocity += this.accel;
+ this.velocity *= ( 1 - friction );
+ this.x += this.velocity;
+ this.accel = 0;
+};
+
+Particle.prototype.applyForce = function( force ) {
+ this.accel += force;
+};
+
+window.Particle = Particle;
+
+})();