Sha256: 1114a3de00eee171eea053495552c6022edf15e9a5c6bcb221e256651c874c8e

Contents?: true

Size: 714 Bytes

Versions: 4

Compression:

Stored size: 714 Bytes

Contents

module Chroma
  module RgbGenerator
    class FromRgbValues < Base
      # @param format [Symbol]          color format
      # @param r      [String, Numeric] red value
      # @param g      [String, Numeric] green value
      # @param b      [String, Numeric] blue value
      # @param a      [String, Numeric] alpha value
      def initialize(format, r, g, b, a = 1)
        @format = format || :rgb
        @r, @g, @b, @a = r, g, b, a
      end

      # Generates a {ColorModes::Rgb}.
      # @return [ColorModes::Rgb]
      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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chroma-0.2.0 lib/chroma/rgb_generator/from_rgb_values.rb
chroma-0.1.0 lib/chroma/rgb_generator/from_rgb_values.rb
chroma-0.0.1 lib/chroma/rgb_generator/from_rgb_values.rb
chroma-0.0.1.alpha.3 lib/chroma/rgb_generator/from_rgb_values.rb