Class: UtilityPalettes::Sequences
- Inherits:
-
Object
- Object
- UtilityPalettes::Sequences
- Defined in:
- lib/utility_palettes/sequences.rb
Class Method Summary collapse
Class Method Details
.hsl(colour, level_change) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/utility_palettes/sequences.rb', line 10 def self.hsl(colour, level_change) colour_hsl = colour.hsl configuration = UtilityPalettes.configuration # Use BigDecimal for precise decimal arithmetic h_value = (BigDecimal(colour_hsl[:h].to_s) - BigDecimal((level_change * configuration.steps_h).to_s)) % 360 s_value = (BigDecimal(colour_hsl[:s].to_s) - BigDecimal((level_change * configuration.steps_s).to_s)).clamp(0, 100) l_value = (BigDecimal(colour_hsl[:l].to_s) - BigDecimal((level_change * configuration.steps_l).to_s)).clamp(0, 100) ColorConverters::Color.new(h: h_value.to_f, s: s_value.to_f, l: l_value.to_f) end |
.rgb(colour, level_change) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/utility_palettes/sequences.rb', line 22 def self.rgb(colour, level_change) colour_rgb = colour.rgb configuration = UtilityPalettes.configuration # Use BigDecimal for precise decimal arithmetic r_value = (BigDecimal(colour_rgb[:r].to_s) - BigDecimal((level_change * configuration.steps_r).to_s)).clamp(0, 255) g_value = (BigDecimal(colour_rgb[:g].to_s) - BigDecimal((level_change * configuration.steps_g).to_s)).clamp(0, 255) b_value = (BigDecimal(colour_rgb[:b].to_s) - BigDecimal((level_change * configuration.steps_b).to_s)).clamp(0, 255) ColorConverters::Color.new(r: r_value.to_f, g: g_value.to_f, b: b_value.to_f) end |