Class: Cura::Color
- Inherits:
-
Object
- Object
- Cura::Color
- Defined in:
- lib/cura/color.rb
Overview
Colors.
Instance Attribute Summary collapse
-
#lab ⇒ Object
readonly
Returns the value of attribute lab.
Class Method Summary collapse
- .black ⇒ Object
- .blue ⇒ Object
-
.default ⇒ Object
The default color to be overidden by adapters.
- .green ⇒ Object
- .red ⇒ Object
- .white ⇒ Object
Instance Method Summary collapse
- #-(other) ⇒ Object
- #<=>(other) ⇒ Object
-
#==(other) ⇒ Boolean
Determing if this color is equivalent to another object.
-
#alpha ⇒ Integer
Get the alpha channel of this color.
-
#alpha=(value) ⇒ Integer
Set the alpha channel of this color.
-
#blue=(value) ⇒ Integer
Set the blue channel of this color.
-
#green ⇒ Integer
Get the green channel of this color.
-
#green=(value) ⇒ Integer
Set the green channel of this color.
- #hex ⇒ Object
- #hsl ⇒ Object
-
#initialize(r = 0, g = 0, b = 0, a = 255) ⇒ Color
constructor
A new instance of Color.
-
#red ⇒ Integer
Get the red channel of this color.
-
#red=(value) ⇒ Integer
Set the red channel of this color.
- #to_a ⇒ Object
- #yiq ⇒ Object
Methods included from Attributes::HasAttributes
Constructor Details
#initialize(r = 0, g = 0, b = 0, a = 255) ⇒ Color
Returns a new instance of Color.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cura/color.rb', line 45 def initialize(r=0, g=0, b=0, a=255) if r.respond_to?(:to_h) super(r.to_h) else @red = r @green = g @blue = b @alpha = a end @lab = rgb_to_lab([@red, @green, @blue]) # TODO: Update on rgb setters? end |
Instance Attribute Details
#lab ⇒ Object (readonly)
Returns the value of attribute lab.
106 107 108 |
# File 'lib/cura/color.rb', line 106 def lab @lab end |
Class Method Details
.black ⇒ Object
23 24 25 |
# File 'lib/cura/color.rb', line 23 def black new end |
.blue ⇒ Object
39 40 41 |
# File 'lib/cura/color.rb', line 39 def blue new(0, 0, 255) end |
.default ⇒ Object
The default color to be overidden by adapters. Usually, for TUI’s to use the terminal theme’s colors. TODO: Remove.
19 20 21 |
# File 'lib/cura/color.rb', line 19 def default super end |
.green ⇒ Object
35 36 37 |
# File 'lib/cura/color.rb', line 35 def green new(0, 255, 0) end |
.red ⇒ Object
31 32 33 |
# File 'lib/cura/color.rb', line 31 def red new(255, 0, 0) end |
.white ⇒ Object
27 28 29 |
# File 'lib/cura/color.rb', line 27 def white new(255, 255, 255) end |
Instance Method Details
#-(other) ⇒ Object
108 109 110 |
# File 'lib/cura/color.rb', line 108 def -(other) delta_e_2000(@lab, other.lab) end |
#<=>(other) ⇒ Object
112 113 114 |
# File 'lib/cura/color.rb', line 112 def <=>(other) self.hsl[0] <=> other.hsl[0] end |
#==(other) ⇒ Boolean
Determing if this color is equivalent to another object.
120 121 122 |
# File 'lib/cura/color.rb', line 120 def ==(other) other.is_a?(Color) ? matches_color?(other) : super end |
#alpha ⇒ Integer
Get the alpha channel of this color.
|
|
# File 'lib/cura/color.rb', line 91
|
#alpha=(value) ⇒ Integer
Set the alpha channel of this color.
102 103 104 |
# File 'lib/cura/color.rb', line 102 [:red, :green, :blue, :alpha].each do |channel| attribute(channel) { |value| convert_and_constrain_value(value) } end |
#blue=(value) ⇒ Integer
Set the blue channel of this color.
|
|
# File 'lib/cura/color.rb', line 80
|
#green ⇒ Integer
Get the green channel of this color.
|
|
# File 'lib/cura/color.rb', line 69
|
#green=(value) ⇒ Integer
Set the green channel of this color.
|
|
# File 'lib/cura/color.rb', line 74
|
#hex ⇒ Object
136 137 138 |
# File 'lib/cura/color.rb', line 136 def hex to_a.each_with_object("") { |part, memo| memo << "%02x" % part } end |
#hsl ⇒ Object
124 125 126 |
# File 'lib/cura/color.rb', line 124 def hsl @hsl ||= rgb_to_hsl(@rgb) end |
#red ⇒ Integer
Get the red channel of this color.
|
|
# File 'lib/cura/color.rb', line 58
|
#red=(value) ⇒ Integer
Set the red channel of this color.
|
|
# File 'lib/cura/color.rb', line 63
|
#to_a ⇒ Object
132 133 134 |
# File 'lib/cura/color.rb', line 132 def to_a [@red, @green, @blue, @alpha] end |
#yiq ⇒ Object
128 129 130 |
# File 'lib/cura/color.rb', line 128 def yiq @yiq ||= rgb_to_yiq(@rgb) end |