From 1681c649fb23fb656db4733c841ccf921906c378 Mon Sep 17 00:00:00 2001 From: Robert Machmer Date: Sat, 9 Jan 2016 12:06:26 +0100 Subject: [PATCH] Add setter for customizing a node's mass --- fd/Node.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fd/Node.lua b/fd/Node.lua index bd66e20..7d2a409 100644 --- a/fd/Node.lua +++ b/fd/Node.lua @@ -23,6 +23,7 @@ function Node.new( id, x, y, anchor, ... ) local px, py = x or 0, y or 0; local ax, ay = 0, 0; local vx, vy = 0, 0; + local mass = DEFAULT_MASS; --- -- Clamps a value to a certain range. @@ -69,7 +70,7 @@ function Node.new( id, x, y, anchor, ... ) dx = dx / distance; dy = dy / distance; - local strength = FORCE_CHARGE * (DEFAULT_MASS / (distance * distance)); + local strength = FORCE_CHARGE * ( mass / ( distance * distance )); applyForce(dx * strength, dy * strength); end @@ -114,6 +115,10 @@ function Node.new( id, x, y, anchor, ... ) return anchor; end + function self:setMass( nmass ) + mass = nmass; + end + return self; end