Class: Knossos::Renderer::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/knossos/renderer/image.rb

Instance Method Summary collapse

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, **options)
  options = defaults.merge(options)

  @grid = grid
  @cell_size = options[:cell_size]
  @background_color = options[:background_color]
  @wall_color = options[:wall_color]

  @image = create_canvas
end

Instance Method Details

#renderObject



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