Class: Ruby2D::Color::Set
- Inherits:
-
Object
- Object
- Ruby2D::Color::Set
- Includes:
- Enumerable
- Defined in:
- lib/ruby2d/color.rb
Overview
An array of colors
Instance Method Summary collapse
-
#[](index) ⇒ Object
Get a color by index.
-
#each(&block) ⇒ Object
Iterate over each color.
-
#first(*args) ⇒ Object
Get the first color, or the first
ncolors if a count is given. -
#initialize(colors) ⇒ Set
constructor
Create a color set from an array of colors.
-
#last(*args) ⇒ Object
Get the last color, or the last
ncolors if a count is given. -
#length ⇒ Object
Get the number of colors in the set.
-
#opacity ⇒ Object
Get the opacity of the first color.
-
#opacity=(opacity) ⇒ Object
Set the opacity for all colors.
-
#vertex(i) ⇒ Object
The color for the i-th vertex.
Constructor Details
Instance Method Details
#[](index) ⇒ Object
Get a color by index
18 19 20 |
# File 'lib/ruby2d/color.rb', line 18 def [](index) @colors[index] end |
#each(&block) ⇒ Object
Iterate over each color
28 29 30 |
# File 'lib/ruby2d/color.rb', line 28 def each(&block) @colors.each(&block) end |
#first(*args) ⇒ Object
Get the first color, or the first n colors if a count is given
33 34 35 |
# File 'lib/ruby2d/color.rb', line 33 def first(*args) @colors.first(*args) end |
#last(*args) ⇒ Object
Get the last color, or the last n colors if a count is given
38 39 40 |
# File 'lib/ruby2d/color.rb', line 38 def last(*args) @colors.last(*args) end |
#length ⇒ Object
Get the number of colors in the set
23 24 25 |
# File 'lib/ruby2d/color.rb', line 23 def length @colors.length end |
#opacity ⇒ Object
Get the opacity of the first color
43 44 45 |
# File 'lib/ruby2d/color.rb', line 43 def opacity @colors.first.opacity end |
#opacity=(opacity) ⇒ Object
Set the opacity for all colors
48 49 50 51 52 53 54 55 56 |
# File 'lib/ruby2d/color.rb', line 48 def opacity=(opacity) unless opacity.is_a?(Numeric) raise ArgumentError, "opacity must be a number between 0.0 and 1.0, got #{opacity.inspect}" end @colors.each do |color| color.opacity = opacity end end |
#vertex(i) ⇒ Object
The color for the i-th vertex. Paired with Color#vertex so per-vertex
rendering code can uniformly call color.vertex(i) whether it holds a
single Color (every vertex is the same) or a Color::Set.
61 62 63 |
# File 'lib/ruby2d/color.rb', line 61 def vertex(i) @colors[i] end |