Class: Neotrellis::Neopixel::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/neotrellis/neopixel.rb

Overview

Define a color to be set on a pixel

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r, g, b) ⇒ Color

Create a new color. R G B values must be between 0 and 255

Parameters:

  • r (Integer)

    Red component

  • g (Integer)

    Green component

  • b (Integer)

    Blue component



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

#bObject (readonly)

R G B components



155
156
157
# File 'lib/neotrellis/neopixel.rb', line 155

def b
  @b
end

#gObject (readonly)

R G B components



155
156
157
# File 'lib/neotrellis/neopixel.rb', line 155

def g
  @g
end

#rObject (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.

Parameters:

  • brightness (Float) (defaults to: 1.0)

    Brightness of the color. Must be between 0.0 and 1.0

Returns:

  • (Array)

    Color values as integer in the order GRB



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