Class: WhirledPeas::Animator::RendererConsumer

Inherits:
Object
  • Object
show all
Defined in:
lib/whirled_peas/animator/renderer_consumer.rb

Instance Method Summary collapse

Constructor Details

#initialize(template_factory, device, width, height) ⇒ RendererConsumer

Returns a new instance of RendererConsumer.



8
9
10
11
12
13
14
15
# File 'lib/whirled_peas/animator/renderer_consumer.rb', line 8

def initialize(template_factory, device, width, height)
  @template_factory = template_factory
  @device = device
  @width = width
  @height = height
  @rendered_frames = []
  @prev_pixel_grid = nil
end

Instance Method Details

#add_frameset(frameset) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/whirled_peas/animator/renderer_consumer.rb', line 17

def add_frameset(frameset)
  frameset.each_frame do |frame, duration, args|
    template = template_factory.build(frame, args)
    pixel_grid = Graphics::Renderer.new(template, width, height).paint
    strokes = prev_pixel_grid.nil? ? pixel_grid.to_s : pixel_grid.diff(prev_pixel_grid)
    rendered_frames << Device::RenderedFrame.new(strokes, duration)
    @prev_pixel_grid = pixel_grid
  end
end

#processObject



27
28
29
# File 'lib/whirled_peas/animator/renderer_consumer.rb', line 27

def process
  device.handle_rendered_frames(rendered_frames)
end