Class: Iroki::Color::TwoGroupGradient
- Defined in:
- lib/iroki/color/two_group_gradient.rb
Instance Attribute Summary collapse
-
#g1_counts ⇒ Object
Returns the value of attribute g1_counts.
-
#g1_rabunds ⇒ Object
Returns the value of attribute g1_rabunds.
-
#g2_counts ⇒ Object
Returns the value of attribute g2_counts.
-
#g2_rabunds ⇒ Object
Returns the value of attribute g2_rabunds.
Attributes inherited from Gradient
#color_hex_codes, #lumins, #max_lumin, #min_lumin, #samples, #single_color
Instance Method Summary collapse
- #calc_hex_codes(g1_rabunds, g2_rabunds) ⇒ Object
- #hex_code(ra1, ra2) ⇒ Object
-
#initialize(samples, g1_counts, g2_counts, min_lumin, max_lumin) ⇒ TwoGroupGradient
constructor
A new instance of TwoGroupGradient.
- #lumin_level(ra1, ra2) ⇒ Object
- #mix_percent(ra1, ra2) ⇒ Object
- #percent_of_group1_color(ra1, ra2) ⇒ Object
Methods inherited from Gradient
#counts_to_rabunds, #patterns, #rabunds_to_lumins, #scale, #scale_reverse
Constructor Details
#initialize(samples, g1_counts, g2_counts, min_lumin, max_lumin) ⇒ TwoGroupGradient
Returns a new instance of TwoGroupGradient.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/iroki/color/two_group_gradient.rb', line 24 def initialize samples, g1_counts, g2_counts, min_lumin, max_lumin assert(samples.count == g1_counts.count && g1_counts.count == g2_counts.count, "Samples and counts are different lengths. " + "Check your biom file.") @min_lumin = min_lumin @max_lumin = max_lumin @samples = samples @g1_counts = g1_counts @g2_counts = g2_counts @g1_rabunds = counts_to_rabunds g1_counts @g2_rabunds = counts_to_rabunds g2_counts @color_hex_codes = calc_hex_codes @g1_rabunds, @g2_rabunds end |
Instance Attribute Details
#g1_counts ⇒ Object
Returns the value of attribute g1_counts.
22 23 24 |
# File 'lib/iroki/color/two_group_gradient.rb', line 22 def g1_counts @g1_counts end |
#g1_rabunds ⇒ Object
Returns the value of attribute g1_rabunds.
22 23 24 |
# File 'lib/iroki/color/two_group_gradient.rb', line 22 def g1_rabunds @g1_rabunds end |
#g2_counts ⇒ Object
Returns the value of attribute g2_counts.
22 23 24 |
# File 'lib/iroki/color/two_group_gradient.rb', line 22 def g2_counts @g2_counts end |
#g2_rabunds ⇒ Object
Returns the value of attribute g2_rabunds.
22 23 24 |
# File 'lib/iroki/color/two_group_gradient.rb', line 22 def g2_rabunds @g2_rabunds end |
Instance Method Details
#calc_hex_codes(g1_rabunds, g2_rabunds) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/iroki/color/two_group_gradient.rb', line 94 def calc_hex_codes g1_rabunds, g2_rabunds g1_rabunds.zip(g2_rabunds).map do |ra1, ra2| if ra1.zero? && ra2.zero? Iroki::Color::GRAY.html else hex_code ra1, ra2 end end end |
#hex_code(ra1, ra2) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/iroki/color/two_group_gradient.rb', line 84 def hex_code ra1, ra2 perc = mix_percent ra1, ra2 col = Iroki::Color::GREEN.mix_with Iroki::Color::BLUE, perc col.luminosity = lumin_level ra1, ra2 col.html end |
#lumin_level(ra1, ra2) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/iroki/color/two_group_gradient.rb', line 68 def lumin_level ra1, ra2 if ra1 > ra2 scale_reverse ra1, new_min=@min_lumin, new_max=@max_lumin, old_min=0.0, old_max=1.0 else scale_reverse ra2, new_min=@min_lumin, new_max=@max_lumin, old_min=0.0, old_max=1.0 end end |
#mix_percent(ra1, ra2) ⇒ Object
64 65 66 |
# File 'lib/iroki/color/two_group_gradient.rb', line 64 def mix_percent ra1, ra2 1 - percent_of_group1_color(ra1, ra2) end |
#percent_of_group1_color(ra1, ra2) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/iroki/color/two_group_gradient.rb', line 46 def percent_of_group1_color ra1, ra2 if ra1 > ra2 1 - scale(ra2 / ra1, new_min=0.0, new_max=0.5, old_min=0.0, old_max=1.0) elsif ra1 < ra2 scale(ra1 / ra2, new_min=0.0, new_max=0.5, old_min=0.0, old_max=1.0) else 0.5 end end |