Class: Flock

Inherits:
Object show all
Defined in:
ext/ruby/qtruby/examples/ruboids/ruboids/Flock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFlock

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

#membersObject (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

#drawObject



24
25
26
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/Flock.rb', line 24

def draw
	@members.each { | boid | boid.draw() }
end

#moveObject



28
29
30
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/Flock.rb', line 28

def move
	@members.each { | boid | boid.move() }
end