Class: Amaze::Formatter::ASCII::Ortho
Instance Attribute Summary
#grid, #options
Instance Method Summary
collapse
#ansi_clear, #cell_size, #char, #clear, #distance, #distance_color, #distances, #grid_color, #initialize, #path?, #path_cell?, #path_color, #render
Instance Method Details
#center ⇒ Object
98
99
100
|
# File 'lib/amaze/formatter/ascii/ortho.rb', line 98
def center
'∙'
end
|
#char_array_height ⇒ Object
86
87
88
|
# File 'lib/amaze/formatter/ascii/ortho.rb', line 86
def char_array_height
y(grid.rows) + 1
end
|
#char_array_width ⇒ Object
82
83
84
|
# File 'lib/amaze/formatter/ascii/ortho.rb', line 82
def char_array_width
x(grid.columns) + 1
end
|
#coord(cell) ⇒ Object
70
71
72
|
# File 'lib/amaze/formatter/ascii/ortho.rb', line 70
def coord cell
[x(cell.column), x(cell.column+1), y(cell.row), y(cell.row+1)]
end
|
#corner ⇒ Object
102
103
104
|
# File 'lib/amaze/formatter/ascii/ortho.rb', line 102
def corner
'+'
end
|
#draw_cell(cell) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/amaze/formatter/ascii/ortho.rb', line 4
def draw_cell cell
left, right, top, bottom = coord cell
char[top][left] = corner.color(grid_color)
char[top][right] = corner.color(grid_color)
char[bottom][left] = corner.color(grid_color)
char[bottom][right] = corner.color(grid_color)
(left+1).upto(right-1) do |i|
char[top][i] = h.color(grid_color) unless cell.linked_to?(:north)
char[bottom][i] = h.color(grid_color) unless cell.linked_to?(:south)
end
(top+1).upto(bottom-1) do |i|
char[i][left] = v.color(grid_color) unless cell.linked_to?(:west)
char[i][right] = v.color(grid_color) unless cell.linked_to?(:east)
end
end
|
#draw_content(cell) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/amaze/formatter/ascii/ortho.rb', line 28
def draw_content cell
left, right, top, bottom = coord cell
my = top + cell_size / 2 + 1
distance(cell).center(cell_size * 3).chars.each_with_index do |c,i|
char[my][left+1+i] = c.color(*distance_color(cell))
end
end
|
#draw_path(cell) ⇒ Object
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
|
# File 'lib/amaze/formatter/ascii/ortho.rb', line 37
def draw_path cell
left, right, top, bottom = coord cell
mx = left + (cell_size * 3 + 1) / 2
my = top + cell_size / 2 + 1
top.upto(my-1) do |i|
char[i][mx] = v.color(path_color) if path?(:north, cell)
end if top <= my-1
(mx+1).upto(right) do |i|
char[my][i] = h.color(path_color) if path?(:east, cell)
end if mx+1 <= right
(my+1).upto(bottom) do |i|
char[i][mx] = v.color(path_color) if path?(:south, cell)
end if my+1 <= bottom
left.upto(mx-1) do |i|
char[my][i] = h.color(path_color) if path?(:west, cell)
end if left <= mx-1
center_char = center
center_char = v if path?(:north, cell) && path?(:south, cell)
center_char = h if path?(:east, cell) && path?(:west, cell)
center_char = corner if [:north, :east, :south, :west].select{|d| path?(d, cell) }.size >= 3
char[my][mx] = center_char.color(path_color)
end
|
#h ⇒ Object
90
91
92
|
# File 'lib/amaze/formatter/ascii/ortho.rb', line 90
def h
'-'
end
|
#v ⇒ Object
94
95
96
|
# File 'lib/amaze/formatter/ascii/ortho.rb', line 94
def v
'|'
end
|
#x(column) ⇒ Object
74
75
76
|
# File 'lib/amaze/formatter/ascii/ortho.rb', line 74
def x column
(cell_size * 3 + 1) * column
end
|
#y(row) ⇒ Object
78
79
80
|
# File 'lib/amaze/formatter/ascii/ortho.rb', line 78
def y row
(cell_size + 1) * row
end
|