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.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cura/color.rb', line 41 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.
102 103 104 |
# File 'lib/cura/color.rb', line 102 def lab @lab end |
Class Method Details
.black ⇒ Object
20 21 22 |
# File 'lib/cura/color.rb', line 20 def black new end |
.blue ⇒ Object
36 37 38 |
# File 'lib/cura/color.rb', line 36 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.
16 17 18 |
# File 'lib/cura/color.rb', line 16 def default super end |
.green ⇒ Object
32 33 34 |
# File 'lib/cura/color.rb', line 32 def green new(0, 255, 0) end |
.red ⇒ Object
28 29 30 |
# File 'lib/cura/color.rb', line 28 def red new(255, 0, 0) end |
.white ⇒ Object
24 25 26 |
# File 'lib/cura/color.rb', line 24 def white new(255, 255, 255) end |
Instance Method Details
#-(other) ⇒ Object
104 105 106 |
# File 'lib/cura/color.rb', line 104 def -(other) delta_e_2000(@lab, other.lab) end |
#<=>(other) ⇒ Object
108 109 110 |
# File 'lib/cura/color.rb', line 108 def <=>(other) hsl[0] <=> other.hsl[0] end |
#==(other) ⇒ Boolean
Determing if this color is equivalent to another object.
116 117 118 |
# File 'lib/cura/color.rb', line 116 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 87
|
#alpha=(value) ⇒ Integer
Set the alpha channel of this color.
98 99 100 |
# File 'lib/cura/color.rb', line 98 [: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 76
|
#green ⇒ Integer
Get the green channel of this color.
|
|
# File 'lib/cura/color.rb', line 65
|
#green=(value) ⇒ Integer
Set the green channel of this color.
|
|
# File 'lib/cura/color.rb', line 70
|
#hex ⇒ Object
132 133 134 |
# File 'lib/cura/color.rb', line 132 def hex to_a.each_with_object("") { |part, memo| memo << "%02x" % part } end |
#hsl ⇒ Object
120 121 122 |
# File 'lib/cura/color.rb', line 120 def hsl @hsl ||= rgb_to_hsl(@rgb) end |
#red ⇒ Integer
Get the red channel of this color.
|
|
# File 'lib/cura/color.rb', line 54
|
#red=(value) ⇒ Integer
Set the red channel of this color.
|
|
# File 'lib/cura/color.rb', line 59
|
#to_a ⇒ Object
128 129 130 |
# File 'lib/cura/color.rb', line 128 def to_a [@red, @green, @blue, @alpha] end |
#yiq ⇒ Object
124 125 126 |
# File 'lib/cura/color.rb', line 124 def yiq @yiq ||= rgb_to_yiq(@rgb) end |