class Theseus::Formatters::ASCII::Orthogonal
Renders an OrthogonalMaze
to an ASCII
representation.
The ASCII
formatter for the OrthogonalMaze
actually supports three different output types:
- :plain
-
Uses standard 7-bit
ASCII
characters. Width is 2x+1, height is y+1. This mode cannot render weave mazes without significant ambiguity. - :unicode
-
Uses unicode characters to render cleaner lines. Width is 3x, height is 2y. This mode has sufficient detail to correctly render mazes with weave!
- :lines
-
Draws passages as lines, using unicode characters. Width is x, height is y. This mode can render weave mazes, but with some ambiguity.
The :plain mode is the default, but you can specify a different one using the :mode option.
You shouldn't ever need to instantiate this class directly. Rather, use OrthogonalMaze#to
(:ascii) (or OrthogonalMaze#to_s
to get the string directly).
Constants
- UTF8_LINES
- UTF8_SPRITES
Public Class Methods
Returns the dimensions of the given maze, rendered in the given mode. The mode
must be :plain
, :unicode
, or :lines
.
# File lib/theseus/formatters/ascii/orthogonal.rb, line 31 def self.dimensions_for(maze, mode) case mode when :plain, nil then [maze.width * 2 + 1, maze.height + 1] when :unicode then [maze.width * 3, maze.height * 2] when :lines then [maze.width, maze.height] else abort "unknown mode #{mode.inspect}" end end
Create and return a fully initialized ASCII
canvas. The options
parameter may specify a :mode
parameter, as described in the documentation for this class.
Theseus::Formatters::ASCII::new
# File lib/theseus/formatters/ascii/orthogonal.rb, line 47 def initialize(maze, options={}) mode = options[:mode] || :plain width, height = self.class.dimensions_for(maze, mode) super(width, height) maze.height.times do |y| length = maze.row_length(y) length.times do |x| case mode when :plain then draw_plain_cell(maze, x, y) when :unicode then draw_unicode_cell(maze, x, y) when :lines then draw_line_cell(maze, x, y) end end end end