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.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cura/color.rb', line 43 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.
104 105 106 |
# File 'lib/cura/color.rb', line 104 def lab @lab end |
Class Method Details
.black ⇒ Object
22 23 24 |
# File 'lib/cura/color.rb', line 22 def black new end |
.blue ⇒ Object
38 39 40 |
# File 'lib/cura/color.rb', line 38 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.
18 19 20 |
# File 'lib/cura/color.rb', line 18 def default super end |
.green ⇒ Object
34 35 36 |
# File 'lib/cura/color.rb', line 34 def green new(0, 255, 0) end |
.red ⇒ Object
30 31 32 |
# File 'lib/cura/color.rb', line 30 def red new(255, 0, 0) end |
.white ⇒ Object
26 27 28 |
# File 'lib/cura/color.rb', line 26 def white new(255, 255, 255) end |
Instance Method Details
#-(other) ⇒ Object
106 107 108 |
# File 'lib/cura/color.rb', line 106 def -(other) delta_e_2000(@lab, other.lab) end |
#<=>(other) ⇒ Object
110 111 112 |
# File 'lib/cura/color.rb', line 110 def <=>(other) hsl[0] <=> other.hsl[0] end |
#==(other) ⇒ Boolean
Determing if this color is equivalent to another object.
118 119 120 |
# File 'lib/cura/color.rb', line 118 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 89
|
#alpha=(value) ⇒ Integer
Set the alpha channel of this color.
100 101 102 |
# File 'lib/cura/color.rb', line 100 [: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 78
|
#green ⇒ Integer
Get the green channel of this color.
|
# File 'lib/cura/color.rb', line 67
|
#green=(value) ⇒ Integer
Set the green channel of this color.
|
# File 'lib/cura/color.rb', line 72
|
#hex ⇒ Object
134 135 136 |
# File 'lib/cura/color.rb', line 134 def hex to_a.each_with_object("") { |part, memo| memo << "%02x" % part } end |
#hsl ⇒ Object
122 123 124 |
# File 'lib/cura/color.rb', line 122 def hsl @hsl ||= rgb_to_hsl(@rgb) end |
#red ⇒ Integer
Get the red channel of this color.
|
# File 'lib/cura/color.rb', line 56
|
#red=(value) ⇒ Integer
Set the red channel of this color.
|
# File 'lib/cura/color.rb', line 61
|
#to_a ⇒ Object
130 131 132 |
# File 'lib/cura/color.rb', line 130 def to_a [@red, @green, @blue, @alpha] end |
#yiq ⇒ Object
126 127 128 |
# File 'lib/cura/color.rb', line 126 def yiq @yiq ||= rgb_to_yiq(@rgb) end |