Class: Theseus::Formatters::PNG::Orthogonal

Inherits:
Theseus::Formatters::PNG show all
Defined in:
lib/theseus/formatters/png/orthogonal.rb

Overview

Renders an OrthogonalMaze to a PNG canvas.

You will almost never access this class directly. Instead, use OrthogonalMaze#to(:png, options) to return the raw PNG data directly.

Constant Summary

Constants inherited from Theseus::Formatters::PNG

ANY_E, ANY_N, ANY_S, ANY_W, DEFAULTS

Instance Attribute Summary

Attributes inherited from Theseus::Formatters::PNG

#options

Instance Method Summary collapse

Methods inherited from Theseus::Formatters::PNG

#clamp, #color_at, #fill_poly, #fill_rect, #line, #move, #to_blob

Constructor Details

#initialize(maze, options = {}) ⇒ Orthogonal

Create and return a fully initialized PNG::Orthogonal object, with the maze rendered. To get the maze data, call #to_blob.

See Theseus::Formatters::PNG for a list of all supported options.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/theseus/formatters/png/orthogonal.rb', line 15

def initialize(maze, options={})
  super

  width  = @options[:outer_padding] * 2 + maze.width * @options[:cell_size]
  height = @options[:outer_padding] * 2 + maze.height * @options[:cell_size]
  
  canvas = ChunkyPNG::Image.new(width, height, @options[:background])

  @d1 = @options[:cell_padding]
  @d2 = @options[:cell_size] - @options[:cell_padding]
  @w1 = (@options[:wall_width] / 2.0).floor
  @w2 = ((@options[:wall_width] - 1) / 2.0).floor

  maze.height.times do |y|
    py = @options[:outer_padding] + y * @options[:cell_size]
    maze.width.times do |x|
      px = @options[:outer_padding] + x * @options[:cell_size]
      draw_cell(canvas, [x, y], px, py, maze[x, y])
    end
  end

  @blob = canvas.to_blob
end