Class: Wx::Colour
- Inherits:
-
Object
- Object
- Wx::Colour
- Defined in:
- lib/weft/wxgui/utilities.rb
Overview
extension to Wx::Colour
Instance Method Summary collapse
-
#mix(other, self_parts = 1, other_parts = 1) ⇒ Object
Create a new colour by mixing
self_parts
ofself
withother_parts
of other.
Instance Method Details
#mix(other, self_parts = 1, other_parts = 1) ⇒ Object
Create a new colour by mixing self_parts
of self
with other_parts
of other. The new colour is produced by applying the following averaging formula to the red, green and blue components of each colour
( colour_1 * conc_1 ) + ( colour_2 * conc_2 )
--------------------------
conc_1 + conc_2
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/weft/wxgui/utilities.rb', line 115 def mix(other, self_parts = 1, other_parts = 1) return self if self_parts.zero? && other_parts.zero? rgb = [ :red, :green, :blue ].map do | component | mix = self.send(component) * self_parts mix += other.send(component) * other_parts mix = mix.to_f mix /= self_parts + other_parts mix.to_i end Wx::Colour.new(*rgb) end |