module Pigment::Color

Represent an abstract color in any format

Public Class Methods

hsl(hue, saturation, lightness, alpha = 1.0)
Alias for: hsla
hsla(hue, saturation, lightness, alpha = 1.0) click to toggle source

@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
Also aliased as: hsl
included(klass) click to toggle source

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
rgb(red, blue, green, alpha = 1.0)
Alias for: rgba
rgba(red, blue, green, alpha = 1.0) click to toggle source

@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
Also aliased as: rgb

Public Instance Methods

analogous() click to toggle source

@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
analogous_include?(*others) click to toggle source

@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
analogous_of?(other) click to toggle source

@param [Object] other @return [Boolean]

# File lib/pigment/color.rb, line 109
def analogous_of?(other)
  other.analogous.include?(self)
end
dup() click to toggle source

@return [Pigment::Color]

# File lib/pigment/color.rb, line 50
def dup
  self.class.new(*to_a)
end
into(color_type) click to toggle source

@param [Class] color_type @return [Pigment::Color]

# File lib/pigment/color.rb, line 45
def into(color_type)
  color_type.convert(self)
end
inverse() click to toggle source

@return [Pigment::Color]

# File lib/pigment/color.rb, line 55
def inverse
  into(Pigment::Color::RGB).inverse.into(self.class)
end
inverse?(other) click to toggle source

@param [Object] other @return [Boolean]

# File lib/pigment/color.rb, line 61
def inverse?(other)
  other.is_a?(Pigment::Color) && self.inverse == other
end
rectangular() click to toggle source

@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
rectangular_include?(*others) click to toggle source

@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
rectangular_of?(other) click to toggle source

@param [Object] other @return [Boolean]

# File lib/pigment/color.rb, line 144
def rectangular_of?(other)
  other.rectangular.include?(self)
end
split() click to toggle source

@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
split_include?(*others) click to toggle source

@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
split_of?(other) click to toggle source

@param [Object] other @return [Boolean]

# File lib/pigment/color.rb, line 91
def split_of?(other)
  other.split.include?(self)
end
tertiary() click to toggle source

@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
tertiary_include?(*others) click to toggle source

@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
tertiary_of?(other) click to toggle source

@param [Object] other @return [Boolean]

# File lib/pigment/color.rb, line 162
def tertiary_of?(other)
  other.tertiary.include?(self)
end
tetradic() click to toggle source

@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
tetradic_include?(*others) click to toggle source

@param [Array<Object>] others @return [Boolean]

# File lib/pigment/color.rb, line 133
def tetradic_include?(*others)
  others.all? { |color| tetradic.include?(color) }
end
tetradic_of?(other) click to toggle source

@param [Object] other @return [Boolean]

# File lib/pigment/color.rb, line 127
def tetradic_of?(other)
  other.tetradic.include?(self)
end
to_hex(with_alpha: true) click to toggle source

@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
to_html(with_alpha: false) click to toggle source

@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
to_ints(with_alpha: true) click to toggle source

@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
triadic() click to toggle source

@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
triadic_include?(*others) click to toggle source

@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
triadic_of?(other) click to toggle source

@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