Class: Cura::Color
- Inherits:
-
Object
- Object
- Cura::Color
- Defined in:
- lib/cura/color.rb
Overview
Colors.
Constant Summary collapse
- RGB_TO_LAB_CACHE =
{}
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 57 58 59 |
# 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 # TODO: Update on rgb setters? rgb = [@red, @green, @blue] @lab = (RGB_TO_LAB_CACHE[rgb] ||= rgb_to_lab(rgb)) # @lab = rgb_to_lab(rgb) end |
Instance Attribute Details
#lab ⇒ Object (readonly)
Returns the value of attribute lab.
109 110 111 |
# File 'lib/cura/color.rb', line 109 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
111 112 113 |
# File 'lib/cura/color.rb', line 111 def -(other) delta_e_2000(@lab, other.lab) end |
#<=>(other) ⇒ Object
115 116 117 |
# File 'lib/cura/color.rb', line 115 def <=>(other) hsl[0] <=> other.hsl[0] end |
#==(other) ⇒ Boolean
Determing if this color is equivalent to another object.
123 124 125 |
# File 'lib/cura/color.rb', line 123 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 94
|
#alpha=(value) ⇒ Integer
Set the alpha channel of this color.
105 106 107 |
# File 'lib/cura/color.rb', line 105 [: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 83
|
#green ⇒ Integer
Get the green channel of this color.
|
|
# File 'lib/cura/color.rb', line 72
|
#green=(value) ⇒ Integer
Set the green channel of this color.
|
|
# File 'lib/cura/color.rb', line 77
|
#hex ⇒ Object
139 140 141 |
# File 'lib/cura/color.rb', line 139 def hex to_a.each_with_object("") { |part, memo| memo << "%02x" % part } end |
#hsl ⇒ Object
127 128 129 |
# File 'lib/cura/color.rb', line 127 def hsl @hsl ||= rgb_to_hsl(@rgb) end |
#red ⇒ Integer
Get the red channel of this color.
|
|
# File 'lib/cura/color.rb', line 61
|
#red=(value) ⇒ Integer
Set the red channel of this color.
|
|
# File 'lib/cura/color.rb', line 66
|
#to_a ⇒ Object
135 136 137 |
# File 'lib/cura/color.rb', line 135 def to_a [@red, @green, @blue, @alpha] end |
#yiq ⇒ Object
131 132 133 |
# File 'lib/cura/color.rb', line 131 def yiq @yiq ||= rgb_to_yiq(@rgb) end |