Class: Borealis::Cluster

Inherits:
Object
  • Object
show all
Defined in:
lib/borealis/cluster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(center) ⇒ Cluster

Returns a new instance of Cluster.



5
6
7
8
# File 'lib/borealis/cluster.rb', line 5

def initialize(center)
  @center = center
  @colors = []
end

Instance Attribute Details

#centerObject (readonly)

Returns the value of attribute center.



3
4
5
# File 'lib/borealis/cluster.rb', line 3

def center
  @center
end

#colorsObject (readonly)

Returns the value of attribute colors.



3
4
5
# File 'lib/borealis/cluster.rb', line 3

def colors
  @colors
end

Instance Method Details

#recenter!Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/borealis/cluster.rb', line 10

def recenter!
  red_sum = green_sum = blue_sum = 0

  colors.each do |color|
    red_sum += color.red
    green_sum += color.green
    blue_sum += color.blue
  end

  old_center = @center
  @center = Color.new(
    red_sum / colors.length,
    green_sum / colors.length,
    blue_sum / colors.length
  )

  @colors.clear

  old_center.rgb_distance_to @center
end