Class: Chroma::Color
- Inherits:
-
Object
- Object
- Chroma::Color
- Includes:
- Attributes, Modifiers, Serializers, Helpers::Bounders
- Defined in:
- lib/chroma/color.rb,
lib/chroma/color/modifiers.rb,
lib/chroma/color/attributes.rb,
lib/chroma/color/serializers.rb
Overview
The main class to represent colors.
Defined Under Namespace
Modules: Attributes, Modifiers, Serializers
Instance Attribute Summary
Attributes included from Serializers
Attributes included from Attributes
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Returns true if both are equal in value.
-
#complement ⇒ Color
Returns the complementary color.
-
#custom_palette(&block) ⇒ Array<Color>
Defines a custom palette and immediately returns it.
-
#eql?(other) ⇒ true, false
Returns true if
self
is equal toother
and they're both instances of Color. -
#initialize(input, format = nil) ⇒ Color
constructor
A new instance of Color.
-
#paint ⇒ self
Returns self.
-
#palette ⇒ Harmonies
Returns an instance of Harmonies from which to call a palette method.
Methods included from Helpers::Bounders
#bound01, #bound_alpha, #clamp01, #to_percentage
Methods included from Modifiers
#brighten, #darken, #desaturate, #grayscale, #lighten, #opacity, #saturate, #spin
Methods included from Serializers
#hsl, #hsv, #to_hex, #to_hex8, #to_hsl, #to_hsv, #to_name, #to_rgb, #to_s
Methods included from Attributes
#alpha, #brightness, #dark?, #light?
Constructor Details
#initialize(input, format = nil) ⇒ Color
Returns a new instance of Color.
11 12 13 14 15 |
# File 'lib/chroma/color.rb', line 11 def initialize(input, format = nil) @input = input @rgb, gen_format = generate_rgb_and_format(input) @format = format || gen_format end |
Instance Method Details
#==(other) ⇒ true, false
Returns true if both are equal in value.
59 60 61 |
# File 'lib/chroma/color.rb', line 59 def ==(other) to_hex == other.to_hex end |
#complement ⇒ Color
Returns the complementary color.
69 70 71 72 73 |
# File 'lib/chroma/color.rb', line 69 def complement hsl = self.hsl hsl.h = (hsl.h + 180) % 360 self.class.new(hsl, @format) end |
#custom_palette(&block) ⇒ Array<Color>
Defines a custom palette and immediately returns it. Uses a DSL inside
block
that mirrors the methods in Modifiers.
97 98 99 |
# File 'lib/chroma/color.rb', line 97 def custom_palette(&block) PaletteBuilder.build(&block).evaluate(self) end |
#eql?(other) ⇒ true, false
Returns true if self
is equal to other
and they're both instances of
Chroma::Color.
43 44 45 |
# File 'lib/chroma/color.rb', line 43 def eql?(other) self.class == other.class && self == other end |
#paint ⇒ self
Returns self. Useful for ducktyping situations with String#paint.
26 27 28 |
# File 'lib/chroma/color.rb', line 26 def paint self end |