Class: Vissen::Output::VixelBuffer
- Inherits:
-
Object
- Object
- Vissen::Output::VixelBuffer
- Includes:
- Buffer
- Defined in:
- lib/vissen/output/vixel_buffer.rb
Overview
Vixel Buffer
TODO: Document this class.
Instance Attribute Summary collapse
-
#intensity ⇒ Float
The global intensity of the buffer.
-
#palette ⇒ Integer
The palette number currently in use.
Attributes included from Buffer
Instance Method Summary collapse
-
#initialize(context, palette: 0, intensity: 1.0) ⇒ VixelBuffer
constructor
A new instance of VixelBuffer.
-
#render(buffer, intensity: 1.0) ⇒ PixelBuffer
Render the layer vixels to the given buffer.
-
#vixel_count ⇒ Integer
The number of vixels in the buffer.
Methods included from Buffer
#[], #each_with_position, #freeze, #share_context?
Constructor Details
#initialize(context, palette: 0, intensity: 1.0) ⇒ VixelBuffer
Returns a new instance of VixelBuffer.
24 25 26 27 28 29 |
# File 'lib/vissen/output/vixel_buffer.rb', line 24 def initialize(context, palette: 0, intensity: 1.0) super(context, Vixel) @palette = palette @intensity = intensity end |
Instance Attribute Details
#intensity ⇒ Float
Returns the global intensity of the buffer.
12 13 14 |
# File 'lib/vissen/output/vixel_buffer.rb', line 12 def intensity @intensity end |
#palette ⇒ Integer
Returns the palette number currently in use.
15 16 17 |
# File 'lib/vissen/output/vixel_buffer.rb', line 15 def palette @palette end |
Instance Method Details
#render(buffer, intensity: 1.0) ⇒ PixelBuffer
Render the layer vixels to the given buffer.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vissen/output/vixel_buffer.rb', line 38 def render(buffer, intensity: 1.0) palette = context.palettes[@palette] buffer.each_with_index do |color, index| vixel = vixels[index] next unless vixel.i.positive? ratio = vixel.i * intensity * @intensity color.mix_with! palette[vixel.p], ratio end buffer end |
#vixel_count ⇒ Integer
Returns the number of vixels in the buffer.
51 52 53 |
# File 'lib/vissen/output/vixel_buffer.rb', line 51 def vixel_count vixels.length end |