Method: Inker::Color#overlay

Defined in:
lib/inker/color.rb

#overlay(color) ⇒ Inker::Color

Calculates the result of 2 colors overlay.

Returns:



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/inker/color.rb', line 149

def overlay(color)
  result = dup
  other = color.to_color

  return result if alpha >= 1

  alpha_weight = other.alpha * (1 - alpha)

  # Calculate the result of the overlay operation.
  3.times do |i|
    result[i] = (self[i] * alpha + other[i] * alpha_weight).round
  end

  result.alpha = alpha + alpha_weight

  result
end