Class: Knossos::Renderer::Image
- Inherits:
-
Object
- Object
- Knossos::Renderer::Image
- Defined in:
- lib/knossos/renderer/image.rb
Instance Method Summary collapse
-
#initialize(grid, **options) ⇒ Image
constructor
A new instance of Image.
- #render ⇒ Object
Constructor Details
#initialize(grid, **options) ⇒ Image
Returns a new instance of Image.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/knossos/renderer/image.rb', line 4 def initialize(grid, **) = defaults.merge() @grid = grid @cell_size = [:cell_size] @background_color = [:background_color] @wall_color = [:wall_color] @image = create_canvas end |
Instance Method Details
#render ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/knossos/renderer/image.rb', line 15 def render grid.each_cell do |cell, row, column| x1, y1, x2, y2 = coordinates_for(row, column) image.line(x1, y1, x2, y1, wall_color) unless grid.north(cell) image.line(x1, y1, x1, y2, wall_color) unless grid.west(cell) image.line(x2, y1, x2, y2, wall_color) unless cell.linked?(grid.east(cell)) image.line(x1, y2, x2, y2, wall_color) unless cell.linked?(grid.south(cell)) end image end |