summaryrefslogtreecommitdiffhomepage
path: root/lib/rules/limit.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-08-09 09:15:38 -0400
committerrealtradam <[email protected]>2021-08-09 09:15:38 -0400
commit501ec02e894865836f2960b0bbc16b3448e3707f (patch)
treead2c1124e5ab5807dea1b11002cc5bf2df1226d9 /lib/rules/limit.rb
parent4e909c6b44794b76ef3a98c032ea90204b673f85 (diff)
downloadruboids-501ec02e894865836f2960b0bbc16b3448e3707f.tar.gz
ruboids-501ec02e894865836f2960b0bbc16b3448e3707f.zip
ruboids!
Diffstat (limited to 'lib/rules/limit.rb')
-rw-r--r--lib/rules/limit.rb13
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