Class: Vissen::Output::VixelStack
- Inherits:
-
Object
- Object
- Vissen::Output::VixelStack
- Extended by:
- Forwardable
- Defined in:
- lib/vissen/output/vixel_stack.rb
Overview
Stack
TODO: Document this class.
Instance Attribute Summary collapse
-
#context ⇒ Context
readonly
The context in which the stack exist.
-
#layers ⇒ Array<VixelBuffer>
readonly
The layers that make up the stack.
Instance Method Summary collapse
-
#[](layer, *args) ⇒ Vixel?
Accesses a vixel in one of the vixelbuffers stored in the stack.
-
#freeze ⇒ self
Prevents more layers and palettes from being added.
-
#initialize(context, layer_count) ⇒ VixelStack
constructor
TODO: Make palettes a keyword argument in the next minor version.
-
#pixel_buffer ⇒ PixelBuffer
A new, uninitialized pixel buffer.
-
#point_count ⇒ Integer
(also: #vixel_count)
The number of points in each layer of the stack.
-
#render(pixel_buffer, intensity: 1.0) ⇒ PixelBuffer
Renders each layer and combines the result in the given buffer.
Constructor Details
#initialize(context, layer_count) ⇒ VixelStack
TODO: Make palettes a keyword argument in the next minor version.
31 32 33 34 35 36 37 38 |
# File 'lib/vissen/output/vixel_stack.rb', line 31 def initialize(context, layer_count) raise RangeError if layer_count <= 0 @context = context @layers = Array.new(layer_count) { VixelBuffer.new context } freeze end |
Instance Attribute Details
#context ⇒ Context (readonly)
Returns the context in which the stack exist.
17 18 19 |
# File 'lib/vissen/output/vixel_stack.rb', line 17 def context @context end |
#layers ⇒ Array<VixelBuffer> (readonly)
Returns the layers that make up the stack.
14 15 16 |
# File 'lib/vissen/output/vixel_stack.rb', line 14 def layers @layers end |
Instance Method Details
#[](layer, *args) ⇒ Vixel?
Accesses a vixel in one of the vixelbuffers stored in the stack.
53 54 55 |
# File 'lib/vissen/output/vixel_stack.rb', line 53 def [](layer, *args) @layers[layer][*args] end |
#freeze ⇒ self
Prevents more layers and palettes from being added.
43 44 45 46 |
# File 'lib/vissen/output/vixel_stack.rb', line 43 def freeze @layers.freeze super end |
#pixel_buffer ⇒ PixelBuffer
Returns a new, uninitialized pixel buffer.
58 59 60 |
# File 'lib/vissen/output/vixel_stack.rb', line 58 def pixel_buffer PixelBuffer.new context end |
#point_count ⇒ Integer Also known as: vixel_count
Returns the number of points in each layer of the stack.
21 |
# File 'lib/vissen/output/vixel_stack.rb', line 21 def_delegators :@context, :point_count |
#render(pixel_buffer, intensity: 1.0) ⇒ PixelBuffer
Renders each layer and combines the result in the given buffer.
TODO: Could we cache the result of this operation at time t to an
internal PixelGrid and copy the stored information for subsequent
requests at or around the same time?
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/vissen/output/vixel_stack.rb', line 76 def render(pixel_buffer, intensity: 1.0) raise ContextError unless context == pixel_buffer.context pixel_buffer.clear! @layers.reduce(pixel_buffer) do |a, e| e.render a, intensity: intensity end pixel_buffer.finalize! end |