Class: Theseus::Formatters::ASCII::Delta
- Inherits:
-
Theseus::Formatters::ASCII
- Object
- Theseus::Formatters::ASCII
- Theseus::Formatters::ASCII::Delta
- Defined in:
- lib/theseus/formatters/ascii/delta.rb
Overview
Renders a DeltaMaze to an ASCII representation, using 4 characters horizontally and 2 characters vertically to represent a single cell.
__
/\ /
/__\/
/\ /\
/__\/__\
/\ /\ /\
/__\/__\/__\
You shouldn’t ever need to instantiate this class directly. Rather, use DeltaMaze#to(:ascii) (or DeltaMaze#to_s to get the string directly).
Instance Attribute Summary
Attributes inherited from Theseus::Formatters::ASCII
Instance Method Summary collapse
-
#initialize(maze, options = {}) ⇒ Delta
constructor
Returns a new Delta canvas for the given maze (which should be an instance of DeltaMaze).
Methods inherited from Theseus::Formatters::ASCII
Constructor Details
#initialize(maze, options = {}) ⇒ Delta
Returns a new Delta canvas for the given maze (which should be an instance of DeltaMaze). The options parameter is not used.
The returned object will be fully initialized, containing an ASCII representation of the given DeltaMaze.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/theseus/formatters/ascii/delta.rb', line 25 def initialize(maze, ={}) super((maze.width + 1) * 2, maze.height * 2 + 1) maze.height.times do |y| py = y * 2 maze.row_length(y).times do |x| cell = maze[x, y] next if cell == 0 px = x * 2 if maze.points_up?(x, y) if cell & Maze::W == 0 self[px+1,py+1] = "/" self[px,py+2] = "/" elsif y < 1 self[px+1,py] = "_" end if cell & Maze::E == 0 self[px+2,py+1] = "\\" self[px+3,py+2] = "\\" elsif y < 1 self[px+2,py] = "_" end if cell & Maze::S == 0 self[px+1,py+2] = self[px+2,py+2] = "_" end else if cell & Maze::W == 0 self[px,py+1] = "\\" self[px+1,py+2] = "\\" elsif x > 0 && maze[x-1,y] & Maze::S == 0 self[px+1,py+2] = "_" end if cell & Maze::E == 0 self[px+3,py+1] = "/" self[px+2,py+2] = "/" elsif x < maze.row_length(y) && maze[x+1,y] & Maze::S == 0 self[px+2,py+2] = "_" end if cell & Maze::N == 0 self[px+1,py] = self[px+2,py] = "_" end end end end end |