summaryrefslogtreecommitdiffhomepage
path: root/lib/rules/limit.rb
blob: c454de43b8a00e647c8d94ecb42b2105d03cd54b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
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