From 441ccfcc2be67aaf7a621e8d43690bad2de498e2 Mon Sep 17 00:00:00 2001 From: Dennis Hotson Date: Sun, 1 Jun 2014 18:29:54 +1000 Subject: [PATCH] Added `tick` for manually stepping through simulation --- springy.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/springy.js b/springy.js index c7c9c9d..51d313a 100644 --- a/springy.js +++ b/springy.js @@ -498,11 +498,7 @@ if (onRenderStart !== undefined) { onRenderStart(); } Springy.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(); @@ -522,6 +518,14 @@ this._stop = true; } + Layout.ForceDirected.prototype.tick = function(timestep) { + this.applyCoulombsLaw(); + this.applyHookesLaw(); + this.attractToCentre(); + this.updateVelocity(timestep); + this.updatePosition(timestep); + }; + // Find the nearest point to a particular position Layout.ForceDirected.prototype.nearest = function(pos) { var min = {node: null, point: null, distance: null};