Class: WhirledPeas::Graphics::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/whirled_peas/graphics/renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(template, width, height) ⇒ Renderer

Returns a new instance of Renderer.



7
8
9
10
11
# File 'lib/whirled_peas/graphics/renderer.rb', line 7

def initialize(template, width, height)
  @template = template
  @width = width
  @height = height
end

Instance Method Details

#paintObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/whirled_peas/graphics/renderer.rb', line 13

def paint
  # Modify the template's settings so that it fills the entire screen
  template.settings.width = width
  template.settings.height = height
  template.settings.sizing = :border
  template.settings.set_margin(left: 0, top: 0, right: 0, bottom: 0)
  pixel_grid = PixelGrid.new(width, height)
  template.paint(Canvas.new(0, 0, width, height), 0, 0) do |left, top, fstring|
    pixel_grid.add_stroke(left, top, fstring)
  end
  pixel_grid
end