class Theseus::Formatters::PNG::Orthogonal

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.

Public Class Methods

new(maze, options={}) click to toggle source

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.

Calls superclass method Theseus::Formatters::PNG::new
# 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