Class: Iroki::Color::SingleGroupGradient

Inherits:
Gradient
  • Object
show all
Defined in:
lib/iroki/color/single_group_gradient.rb

Instance Attribute Summary collapse

Attributes inherited from Gradient

#color_hex_codes, #lumins, #samples, #single_color

Instance Method Summary collapse

Methods inherited from Gradient

#counts_to_rabunds, #patterns, #rabunds_to_lumins, #scale, #scale_reverse

Constructor Details

#initialize(samples, counts, single_color = false) ⇒ SingleGroupGradient

Returns a new instance of SingleGroupGradient.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/iroki/color/single_group_gradient.rb', line 24

def initialize samples, counts, single_color=false
  abort_unless samples.count == counts.count,
               "Samples (#{samples.count}) and counts " +
               "#{counts.count} are different size."

  @single_color = single_color
  @samples = samples
  @counts = counts
  @rel_abunds = counts_to_rabunds counts
  @lumins = rabunds_to_lumins @rel_abunds

  if @single_color
    @color_hex_codes = single_color_gradient_hex_codes
  else
    @color_hex_codes = two_color_gradient_hex_codes
  end
end

Instance Attribute Details

#countsObject

Returns the value of attribute counts.



22
23
24
# File 'lib/iroki/color/single_group_gradient.rb', line 22

def counts
  @counts
end

#rel_abundsObject

Returns the value of attribute rel_abunds.



22
23
24
# File 'lib/iroki/color/single_group_gradient.rb', line 22

def rel_abunds
  @rel_abunds
end

Instance Method Details

#single_color_gradient_hex_codesObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/iroki/color/single_group_gradient.rb', line 55

def single_color_gradient_hex_codes
  @rel_abunds.zip(@lumins).map do |rel_abund, lumin|
    amt_of_orig_color =
      scale rel_abund, new_min=10, new_max=95

    col =
      Iroki::Color::DARK_GREEN.lighten_by amt_of_orig_color

    col.html
  end
end

#two_color_gradient_hex_codesObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/iroki/color/single_group_gradient.rb', line 42

def two_color_gradient_hex_codes
  @rel_abunds.map.with_index do |rel_abund, idx|
    lumin = @lumins[idx]

    col =
      Iroki::Color::GREEN.mix_with Iroki::Color::BLUE, rel_abund

    col.luminosity = lumin

    col.html
  end
end