Class: Flock
- Defined in:
- ext/ruby/qtruby/examples/ruboids/ruboids/Flock.rb
Instance Attribute Summary collapse
-
#members ⇒ Object
readonly
Returns the value of attribute members.
Instance Method Summary collapse
- #add(boid) ⇒ Object
-
#centerExcluding(b) ⇒ Object
Center of mass.
-
#distBetween(b1, b2) ⇒ Object
Return distance between two boid’s positions.
- #draw ⇒ Object
-
#initialize ⇒ Flock
constructor
A new instance of Flock.
- #move ⇒ Object
Constructor Details
#initialize ⇒ Flock
Returns a new instance of Flock.
15 16 17 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/Flock.rb', line 15 def initialize @members = [] end |
Instance Attribute Details
#members ⇒ Object (readonly)
Returns the value of attribute members.
13 14 15 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/Flock.rb', line 13 def members @members end |
Instance Method Details
#add(boid) ⇒ Object
19 20 21 22 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/Flock.rb', line 19 def add(boid) @members << boid boid.flock = self end |
#centerExcluding(b) ⇒ Object
Center of mass
38 39 40 41 42 43 44 45 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/Flock.rb', line 38 def centerExcluding(b) p = Point.new() @members.each { | boid | p.addPoint(boid.position) unless boid == b } p.divideBy(@members.length - 1) return p end |
#distBetween(b1, b2) ⇒ Object
Return distance between two boid’s positions.
33 34 35 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/Flock.rb', line 33 def distBetween(b1, b2) return b1.position.distanceTo(b2.position) end |
#draw ⇒ Object
24 25 26 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/Flock.rb', line 24 def draw @members.each { | boid | boid.draw() } end |
#move ⇒ Object
28 29 30 |
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/Flock.rb', line 28 def move @members.each { | boid | boid.move() } end |