diff options
Diffstat (limited to 'lib/rules/limit.rb')
| -rw-r--r-- | lib/rules/limit.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/rules/limit.rb b/lib/rules/limit.rb new file mode 100644 index 0000000..c454de4 --- /dev/null +++ b/lib/rules/limit.rb @@ -0,0 +1,13 @@ +# This special function is already called by apply_boid_calculations.rb +# do not add or call this function elsewhere +FF::Sys.new('Limit') do + unless $limit < 0 + FF::Cmp::Boids.each do |boid| + absolute_velocity = Math.sqrt((boid.vx**2) + (boid.vy**2)) + if absolute_velocity > $limit + boid.vx = (boid.vx / absolute_velocity) * $limit + boid.vy = (boid.vy / absolute_velocity) * $limit + end + end + end +end |
