Class: Vissen::Output::VixelBuffer

Inherits:
Object
  • Object
show all
Includes:
Buffer
Defined in:
lib/vissen/output/vixel_buffer.rb

Overview

Vixel Buffer

TODO: Document this class.

Instance Attribute Summary collapse

Attributes included from Buffer

#context, #elements

Instance Method Summary collapse

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.

Parameters:

  • context (Context)

    the context in which the buffer exists.

  • palette (Integer) (defaults to: 0)

    the palette number to use when rendering.

  • intensity (Numeric) (defaults to: 1.0)

    the global intensity at which to render.



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

#intensityFloat

Returns the global intensity of the buffer.

Returns:

  • (Float)

    the global intensity of the buffer.



12
13
14
# File 'lib/vissen/output/vixel_buffer.rb', line 12

def intensity
  @intensity
end

#paletteInteger

Returns the palette number currently in use.

Returns:

  • (Integer)

    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.

Parameters:

  • buffer (PixelBuffer)

    the buffer to store the resulting colors of each point in.

  • intensity (Numeric) (defaults to: 1.0)

    the intensity to scale the vixels intensity with.

Returns:

  • (PixelBuffer)

    the same buffer that was given as a parameter.



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_countInteger

Returns the number of vixels in the buffer.

Returns:

  • (Integer)

    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