Module: Abachrome::ColorMixins::SpectralMix
- Defined in:
- lib/abachrome/color_mixins/spectral_mix.rb
Instance Method Summary collapse
-
#spectral_mix(other, amount = 0.5, tinting_strength_self: 1.0, tinting_strength_other: 1.0) ⇒ Abachrome::Color
Mix this color with another color using Kubelka-Munk spectral mixing.
Instance Method Details
#spectral_mix(other, amount = 0.5, tinting_strength_self: 1.0, tinting_strength_other: 1.0) ⇒ Abachrome::Color
Mix this color with another color using Kubelka-Munk spectral mixing.
This method produces more realistic color mixing than simple RGB or LAB interpolation by simulating how real pigments absorb and scatter light.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/abachrome/color_mixins/spectral_mix.rb', line 46 def spectral_mix(other, amount = 0.5, tinting_strength_self: 1.0, tinting_strength_other: 1.0) require_relative "../spectral" # Convert amount to weights # amount = 0 means 100% self, 0% other # amount = 0.5 means 50% self, 50% other # amount = 1 means 0% self, 100% other weight_self = 1.0 - amount.to_f weight_other = amount.to_f colors = [ { color: self, weight: weight_self }, { color: other, weight: weight_other } ] tinting_strengths = { self => tinting_strength_self.to_f, other => tinting_strength_other.to_f } Spectral.mix(colors, tinting_strengths: tinting_strengths) end |