Class: Chroma::RgbGenerator::FromRgbValues

Inherits:
Base
  • Object
show all
Defined in:
lib/chroma/rgb_generator/from_rgb_values.rb

Instance Method Summary collapse

Methods included from Helpers::Bounders

#bound01, #bound_alpha, #clamp01, #to_percentage

Constructor Details

#initialize(format, r, g, b, a = 1) ⇒ FromRgbValues

Returns a new instance of FromRgbValues.

Parameters:

  • format (Symbol)

    color format

  • r (String, Numeric)

    red value

  • g (String, Numeric)

    green value

  • b (String, Numeric)

    blue value

  • a (String, Numeric) (defaults to: 1)

    alpha value



9
10
11
12
# File 'lib/chroma/rgb_generator/from_rgb_values.rb', line 9

def initialize(format, r, g, b, a = 1)
  @format = format || :rgb
  @r, @g, @b, @a = r, g, b, a
end

Instance Method Details

#generateColorModes::Rgb

Generates a ColorModes::Rgb.

Returns:



16
17
18
19
20
# File 'lib/chroma/rgb_generator/from_rgb_values.rb', line 16

def generate
  r, g, b = [@r, @g, @b].map { |n| bound01(n, 255) * 255 }
  a = bound_alpha(@a)
  [ColorModes::Rgb.new(r, g, b, a), @format]
end