Class: Emf::Model::Geometry::Color
- Inherits:
-
Object
- Object
- Emf::Model::Geometry::Color
- Defined in:
- lib/emf/model/geometry/color.rb
Instance Attribute Summary collapse
-
#alpha ⇒ Object
readonly
Returns the value of attribute alpha.
-
#blue ⇒ Object
readonly
Returns the value of attribute blue.
-
#green ⇒ Object
readonly
Returns the value of attribute green.
-
#red ⇒ Object
readonly
Returns the value of attribute red.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(red:, green:, blue:, alpha: 255) ⇒ Color
constructor
A new instance of Color.
- #inspect ⇒ Object
- #to_hex ⇒ Object
- #to_hex_rgba ⇒ Object
- #to_wire ⇒ Object
Constructor Details
#initialize(red:, green:, blue:, alpha: 255) ⇒ Color
Returns a new instance of Color.
7 8 9 10 11 12 |
# File 'lib/emf/model/geometry/color.rb', line 7 def initialize(red:, green:, blue:, alpha: 255) @red = coerce(red) @green = coerce(green) @blue = coerce(blue) @alpha = coerce(alpha) end |
Instance Attribute Details
#alpha ⇒ Object (readonly)
Returns the value of attribute alpha.
14 15 16 |
# File 'lib/emf/model/geometry/color.rb', line 14 def alpha @alpha end |
#blue ⇒ Object (readonly)
Returns the value of attribute blue.
14 15 16 |
# File 'lib/emf/model/geometry/color.rb', line 14 def blue @blue end |
#green ⇒ Object (readonly)
Returns the value of attribute green.
14 15 16 |
# File 'lib/emf/model/geometry/color.rb', line 14 def green @green end |
#red ⇒ Object (readonly)
Returns the value of attribute red.
14 15 16 |
# File 'lib/emf/model/geometry/color.rb', line 14 def red @red end |
Class Method Details
.black ⇒ Object
32 33 34 |
# File 'lib/emf/model/geometry/color.rb', line 32 def self.black new(red: 0, green: 0, blue: 0) end |
.from_wire(wire) ⇒ Object
16 17 18 |
# File 'lib/emf/model/geometry/color.rb', line 16 def self.from_wire(wire) new(red: wire.red, green: wire.green, blue: wire.blue, alpha: wire.reserved.zero? ? 255 : wire.reserved) end |
.transparent ⇒ Object
40 41 42 |
# File 'lib/emf/model/geometry/color.rb', line 40 def self.transparent new(red: 0, green: 0, blue: 0, alpha: 0) end |
.white ⇒ Object
36 37 38 |
# File 'lib/emf/model/geometry/color.rb', line 36 def self.white new(red: 255, green: 255, blue: 255) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
44 45 46 47 48 |
# File 'lib/emf/model/geometry/color.rb', line 44 def ==(other) other.is_a?(self.class) && red == other.red && green == other.green && blue == other.blue && alpha == other.alpha end |
#hash ⇒ Object
51 52 53 |
# File 'lib/emf/model/geometry/color.rb', line 51 def hash [self.class, red, green, blue, alpha].hash end |
#inspect ⇒ Object
55 56 57 |
# File 'lib/emf/model/geometry/color.rb', line 55 def inspect "#<#{self.class.name} #{to_hex_rgba}>" end |
#to_hex ⇒ Object
24 25 26 |
# File 'lib/emf/model/geometry/color.rb', line 24 def to_hex alpha == 255 ? format("#%02X%02X%02X", red, green, blue) : to_hex_rgba end |
#to_hex_rgba ⇒ Object
28 29 30 |
# File 'lib/emf/model/geometry/color.rb', line 28 def to_hex_rgba format("#%02X%02X%02X%02X", red, green, blue, alpha) end |