Class: Dvl::Color::FakeRgba

Inherits:
Object
  • Object
show all
Defined in:
lib/dvl/color/fake_rgba.rb

Class Method Summary collapse

Class Method Details

.calculate(background, foreground, alpha) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'lib/dvl/color/fake_rgba.rb', line 2

def self.calculate(background, foreground, alpha)
  bg = background.rgb
  fg = foreground.rgb

  r = (fg.r * alpha) + (bg.r * (1 - alpha))
  g = (fg.g * alpha) + (bg.g * (1 - alpha))
  b = (fg.b * alpha) + (bg.b * (1 - alpha))

  Chroma::Color.new(Chroma::ColorModes::Rgb.new(r, g,  b), :hex)
end