Class: Iroki::Color::Gradient
- Inherits:
-
Object
- Object
- Iroki::Color::Gradient
- Defined in:
- lib/iroki/color/gradient.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#color_hex_codes ⇒ Object
Returns the value of attribute color_hex_codes.
-
#lumins ⇒ Object
Returns the value of attribute lumins.
-
#max_lumin ⇒ Object
Returns the value of attribute max_lumin.
-
#min_lumin ⇒ Object
Returns the value of attribute min_lumin.
-
#samples ⇒ Object
Returns the value of attribute samples.
-
#single_color ⇒ Object
Returns the value of attribute single_color.
Instance Method Summary collapse
- #counts_to_rabunds(counts) ⇒ Object
- #patterns ⇒ Object
- #rabunds_to_lumins(rabunds) ⇒ Object
-
#scale(x, new_min = 0.05, new_max = 0.9, old_min = 0.0, old_max = 1.0) ⇒ Object
scales [old_min, old_max] to [new_min, new_max].
-
#scale_reverse(x, new_min = 0.0, new_max = 0.0, old_min = 0.0, old_max = 1.0) ⇒ Object
scales [old_min, old_max] to [new_max, new_min].
Instance Attribute Details
#color_hex_codes ⇒ Object
Returns the value of attribute color_hex_codes.
22 23 24 |
# File 'lib/iroki/color/gradient.rb', line 22 def color_hex_codes @color_hex_codes end |
#lumins ⇒ Object
Returns the value of attribute lumins.
22 23 24 |
# File 'lib/iroki/color/gradient.rb', line 22 def lumins @lumins end |
#max_lumin ⇒ Object
Returns the value of attribute max_lumin.
22 23 24 |
# File 'lib/iroki/color/gradient.rb', line 22 def max_lumin @max_lumin end |
#min_lumin ⇒ Object
Returns the value of attribute min_lumin.
22 23 24 |
# File 'lib/iroki/color/gradient.rb', line 22 def min_lumin @min_lumin end |
#samples ⇒ Object
Returns the value of attribute samples.
22 23 24 |
# File 'lib/iroki/color/gradient.rb', line 22 def samples @samples end |
#single_color ⇒ Object
Returns the value of attribute single_color.
22 23 24 |
# File 'lib/iroki/color/gradient.rb', line 22 def single_color @single_color end |
Instance Method Details
#counts_to_rabunds(counts) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/iroki/color/gradient.rb', line 71 def counts_to_rabunds counts max_count = counts.max.to_f counts.map do |count| count / max_count end end |
#patterns ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/iroki/color/gradient.rb', line 61 def patterns hash = {} @samples.zip(@color_hex_codes).each do |(sample, hexcode)| tag = Iroki::Color.get_tag hexcode hash[sample] = { label: tag, branch: tag } end hash end |
#rabunds_to_lumins(rabunds) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/iroki/color/gradient.rb', line 79 def rabunds_to_lumins rabunds rabunds.map do |count| # scale_reverse count, new_min=50, new_max=97 # scale_reverse count, new_min=35, new_max=85 scale_reverse count, new_min=@min_lumin, new_max=@max_lumin # scale_reverse count, 0.0, 50.0 end end |
#scale(x, new_min = 0.05, new_max = 0.9, old_min = 0.0, old_max = 1.0) ⇒ Object
scales [old_min, old_max] to [new_min, new_max]
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/iroki/color/gradient.rb', line 30 def scale x, new_min=0.05, new_max=0.9, old_min=0.0, old_max=1.0 x = x.to_f new_min = new_min.to_f new_max = new_max.to_f old_min = old_min.to_f old_max = old_max.to_f ((((new_max - new_min) * (x - old_min.to_f)) / (old_max - old_min)) + new_min) end |
#scale_reverse(x, new_min = 0.0, new_max = 0.0, old_min = 0.0, old_max = 1.0) ⇒ Object
scales [old_min, old_max] to [new_max, new_min]
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/iroki/color/gradient.rb', line 46 def scale_reverse x, new_min=0.0, new_max=0.0, old_min=0.0, old_max=1.0 x = x.to_f new_min = new_min.to_f new_max = new_max.to_f old_min = old_min.to_f old_max = old_max.to_f (new_max - ((((new_max - new_min) * (x - old_min.to_f)) / (old_max - old_min)) + new_min)) + new_min end |