Class: Neotrellis::Neopixel::Color
- Inherits:
-
Object
- Object
- Neotrellis::Neopixel::Color
- Defined in:
- lib/neotrellis/neopixel.rb
Overview
Define a color to be set on a pixel
Instance Attribute Summary collapse
-
#b ⇒ Object
readonly
R G B components.
-
#g ⇒ Object
readonly
R G B components.
-
#r ⇒ Object
readonly
R G B components.
Instance Method Summary collapse
-
#initialize(r, g, b) ⇒ Color
constructor
Create a new color.
-
#to_b(brightness = 1.0) ⇒ Array
Apply a brightness to the color.
Constructor Details
#initialize(r, g, b) ⇒ Color
Create a new color. R G B values must be between 0 and 255
163 164 165 166 167 |
# File 'lib/neotrellis/neopixel.rb', line 163 def initialize(r, g, b) @r = within_range(r) @g = within_range(g) @b = within_range(b) end |
Instance Attribute Details
#b ⇒ Object (readonly)
R G B components
155 156 157 |
# File 'lib/neotrellis/neopixel.rb', line 155 def b @b end |
#g ⇒ Object (readonly)
R G B components
155 156 157 |
# File 'lib/neotrellis/neopixel.rb', line 155 def g @g end |
#r ⇒ Object (readonly)
R G B components
155 156 157 |
# File 'lib/neotrellis/neopixel.rb', line 155 def r @r end |
Instance Method Details
#to_b(brightness = 1.0) ⇒ Array
Apply a brightness to the color.
174 175 176 177 |
# File 'lib/neotrellis/neopixel.rb', line 174 def to_b(brightness = 1.0) # Order is GRB [(@g*brightness).to_i, (@r*brightness).to_i, (@b*brightness).to_i] end |