Class: Vizcore::Renderer::SnapshotRenderer
- Inherits:
-
Object
- Object
- Vizcore::Renderer::SnapshotRenderer
- Defined in:
- lib/vizcore/renderer/snapshot_renderer.rb
Overview
Renders a deterministic software preview PNG from a scene frame.
Defined Under Namespace
Classes: Canvas
Constant Summary collapse
- DEFAULT_WIDTH =
1280- DEFAULT_HEIGHT =
720- PATH_DEFAULT_MAX_SEGMENTS =
4096- PATH_HARD_MAX_SEGMENTS =
65_536- PATH_MAX_RECURSION =
12- PALETTE =
[ [56, 189, 248], [225, 29, 72], [101, 255, 176], [244, 114, 182], [250, 204, 21] ].freeze
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(width: DEFAULT_WIDTH, height: DEFAULT_HEIGHT) ⇒ SnapshotRenderer
constructor
A new instance of SnapshotRenderer.
-
#render(scene:, audio:) ⇒ String
PNG bytes.
Constructor Details
#initialize(width: DEFAULT_WIDTH, height: DEFAULT_HEIGHT) ⇒ SnapshotRenderer
Returns a new instance of SnapshotRenderer.
22 23 24 25 |
# File 'lib/vizcore/renderer/snapshot_renderer.rb', line 22 def initialize(width: DEFAULT_WIDTH, height: DEFAULT_HEIGHT) @width = normalize_dimension(width) @height = normalize_dimension(height) end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
27 28 29 |
# File 'lib/vizcore/renderer/snapshot_renderer.rb', line 27 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
27 28 29 |
# File 'lib/vizcore/renderer/snapshot_renderer.rb', line 27 def width @width end |
Instance Method Details
#render(scene:, audio:) ⇒ String
Returns PNG bytes.
32 33 34 35 36 37 38 39 |
# File 'lib/vizcore/renderer/snapshot_renderer.rb', line 32 def render(scene:, audio:) canvas = Canvas.new(width: width, height: height) canvas.fill_gradient(background_top(audio), background_bottom(audio)) layers = Array(scene[:layers] || scene["layers"]) layers = [default_layer] if layers.empty? layers.each_with_index { |layer, index| render_layer(canvas, layer, audio, index) } PngWriter.encode(width: width, height: height, rgba: canvas.bytes) end |