From f13bd765524a833f2579b146aecd0ce2e0d4140d Mon Sep 17 00:00:00 2001 From: Dennis Hotson Date: Thu, 14 Mar 2013 23:19:16 +1100 Subject: [PATCH] Option to manually tick simulation forward --- springy.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/springy.js b/springy.js index bb15d15..a4df2d5 100644 --- a/springy.js +++ b/springy.js @@ -462,6 +462,14 @@ Layout.requestAnimationFrame = __bind(window.requestAnimationFrame || }, window); +Layout.ForceDirected.prototype.tick = function(timestep) { + this.applyCoulombsLaw(); + this.applyHookesLaw(); + this.attractToCentre(); + this.updateVelocity(timestep); + this.updatePosition(timestep); +}; + // start simulation Layout.ForceDirected.prototype.start = function(render, done) { var t = this; @@ -471,11 +479,8 @@ Layout.ForceDirected.prototype.start = function(render, done) { this._stop = false; Layout.requestAnimationFrame(function step() { - t.applyCoulombsLaw(); - t.applyHookesLaw(); - t.attractToCentre(); - t.updateVelocity(0.03); - t.updatePosition(0.03); + + t.tick(0.03); if (render !== undefined) { render();