module Pigment::Color
Represent an abstract color in any format
Public Class Methods
@param [Integer] hue between 0 and 360 degrees @param [#to_f] saturation between 0.0 and 1.0 @param [#to_f] lightness between 0.0 and 1.0 @param [#to_f] alpha between 0.0 and 1.0 @return [Pigment::Color::HSL]
# File lib/pigment/color.rb, line 21 def hsla(hue, saturation, lightness, alpha = 1.0) Pigment::Color::HSL.from_hue_angle(hue, saturation, lightness, alpha) end
sets aliases for any color format @param [Class] klass
# File lib/pigment/color.rb, line 30 def included(klass) klass.alias_method :gray?, :grayscale? klass.alias_method :-@, :inverse klass.alias_method :inv, :inverse klass.alias_method :invert, :inverse klass.alias_method :complementary, :inverse klass.alias_method :complement, :inverse klass.alias_method :to_floats, :to_a klass.alias_method :to_f, :to_a klass.alias_method :inspect, :to_s end
@param [#to_f] red @param [#to_f] blue @param [#to_f] green @param [#to_f] alpha @return [Pigment::Color::RGB]
# File lib/pigment/color.rb, line 12 def rgba(red, blue, green, alpha = 1.0) Pigment::Color::RGB.new(red, blue, green, alpha) end
Public Instance Methods
@return [Array<Pigment::Color>]
# File lib/pigment/color.rb, line 103 def analogous into(Pigment::Color::HSL).analogous.map { |color| color.into(self.class) } end
@param [Array<Object>] others @return [Boolean]
# File lib/pigment/color.rb, line 115 def analogous_include?(*others) colors = analogous others.all? { |color| colors.include?(color) } end
@param [Object] other @return [Boolean]
# File lib/pigment/color.rb, line 109 def analogous_of?(other) other.analogous.include?(self) end
@return [Pigment::Color]
# File lib/pigment/color.rb, line 50 def dup self.class.new(*to_a) end
@param [Class] color_type @return [Pigment::Color]
# File lib/pigment/color.rb, line 45 def into(color_type) color_type.convert(self) end
@return [Pigment::Color]
# File lib/pigment/color.rb, line 55 def inverse into(Pigment::Color::RGB).inverse.into(self.class) end
@param [Object] other @return [Boolean]
# File lib/pigment/color.rb, line 61 def inverse?(other) other.is_a?(Pigment::Color) && self.inverse == other end
@return [Array<Pigment::Color>]
# File lib/pigment/color.rb, line 138 def rectangular into(Pigment::Color::HSL).rectangular.map { |color| color.into(self.class) } end
@param [Array<Object>] others @return [Boolean]
# File lib/pigment/color.rb, line 150 def rectangular_include?(*others) colors = rectangular others.all? { |color| colors.include?(color) } end
@param [Object] other @return [Boolean]
# File lib/pigment/color.rb, line 144 def rectangular_of?(other) other.rectangular.include?(self) end
@return [Array<Pigment::Color>]
# File lib/pigment/color.rb, line 85 def split into(Pigment::Color::HSL).split.map { |color| color.into(self.class) } end
@param [Array<Object>] others @return [Boolean]
# File lib/pigment/color.rb, line 97 def split_include?(*others) colors = split others.all? { |color| colors.include?(color) } end
@param [Object] other @return [Boolean]
# File lib/pigment/color.rb, line 91 def split_of?(other) other.split.include?(self) end
@return [Array<Pigment::Color>]
# File lib/pigment/color.rb, line 156 def tertiary into(Pigment::Color::HSL).tertiary.map { |color| color.into(self.class) } end
@param [Array<Object>] others @return [Boolean]
# File lib/pigment/color.rb, line 168 def tertiary_include?(*others) colors = tertiary others.all? { |color| colors.include?(color) } end
@param [Object] other @return [Boolean]
# File lib/pigment/color.rb, line 162 def tertiary_of?(other) other.tertiary.include?(self) end
@return [Array<Pigment::Color>]
# File lib/pigment/color.rb, line 121 def tetradic into(Pigment::Color::HSL).tetradic.map { |color| color.into(self.class) } end
@param [Array<Object>] others @return [Boolean]
# File lib/pigment/color.rb, line 133 def tetradic_include?(*others) others.all? { |color| tetradic.include?(color) } end
@param [Object] other @return [Boolean]
# File lib/pigment/color.rb, line 127 def tetradic_of?(other) other.tetradic.include?(self) end
@param [Boolean] with_alpha @return [String]
# File lib/pigment/color.rb, line 187 def to_hex(with_alpha: true) into(Pigment::Color::RGB).to_hex(with_alpha: with_alpha) end
@param [Boolean] with_alpha @return [String]
# File lib/pigment/color.rb, line 175 def to_html(with_alpha: false) "##{to_hex(with_alpha: with_alpha)}" end
@param [Boolean] with_alpha @return [Array<Integer>]
# File lib/pigment/color.rb, line 181 def to_ints(with_alpha: true) into(Pigment::Color::RGB).to_ints(with_alpha: with_alpha) end
@return [Array<Pigment::Color>]
# File lib/pigment/color.rb, line 66 def triadic into(Pigment::Color::RGB).triadic.map { |color| color.into(self.class) } end
@param [Array<Object>] others @return [Boolean]
# File lib/pigment/color.rb, line 79 def triadic_include?(*others) colors = triadic others.all? { |color| colors.include?(color) } end
@param [Object] other @return [Boolean]
# File lib/pigment/color.rb, line 72 def triadic_of?(other) other.into(self.class) other.triadic.include?(self) end