Class: Amaze::Formatter::ASCII::Delta
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
#char_array_height ⇒ Object
100
101
102
|
# File 'lib/amaze/formatter/ascii/delta.rb', line 100
def char_array_height
ypos(grid.rows) + 1
end
|
#char_array_width ⇒ Object
96
97
98
|
# File 'lib/amaze/formatter/ascii/delta.rb', line 96
def char_array_width
xpos(grid.columns + 1) + 1
end
|
#coord(cell) ⇒ Object
84
85
86
|
# File 'lib/amaze/formatter/ascii/delta.rb', line 84
def coord cell
[xpos(cell.column), ypos(cell.row)]
end
|
#corner ⇒ Object
Also known as:
center
120
121
122
|
# File 'lib/amaze/formatter/ascii/delta.rb', line 120
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/amaze/formatter/ascii/delta.rb', line 4
def draw_cell cell
x0, y0 = coord cell
if (cell.column + cell.row).even?
char[y0][x0] = corner.color(grid_color)
char[y0][x0+(cell_size+1)*2] = corner.color(grid_color)
char[y0+cell_size+1][x0+cell_size+1] = corner.color(grid_color)
0.upto(cell_size*2) do |i|
char[y0][x0+1+i] = h.color(grid_color)
end unless cell.linked_to?(:north)
1.upto(cell_size) do |i|
char[y0+i][x0+i] = rw.color(grid_color) unless cell.linked_to?(:west)
char[y0+i][x0+(cell_size+1)*2-i] = re.color(grid_color) unless cell.linked_to?(:east)
end
else
char[y0+cell_size+1][x0] = corner.color(grid_color)
char[y0+cell_size+1][x0+(cell_size+1)*2] = corner.color(grid_color)
char[y0][x0+cell_size+1] = corner.color(grid_color)
0.upto(cell_size*2) do |i|
char[y0+cell_size+1][x0+1+i] = h.color(grid_color)
end unless cell.linked_to?(:south)
1.upto(cell_size) do |i|
char[y0+i][x0+cell_size+1-i] = nw.color(grid_color) unless cell.linked_to?(:west)
char[y0+i][x0+cell_size+1+i] = ne.color(grid_color) unless cell.linked_to?(:east)
end
end
end
|
#draw_content(cell) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/amaze/formatter/ascii/delta.rb', line 46
def draw_content cell
x0, y0 = coord cell
if cell_size == 1
my = y0 + 1
mx = x0 + 2
w = 1
else
mx = x0 + cell_size / 2 + 1
w = (cell_size+1) / 2 * 2 + 1
if (cell.column+cell.row).even?
my = y0 + cell_size / 2
else
my = y0 + (cell_size+3) / 2
end
end
distance(cell).center(w).chars.each_with_index do |c,i|
char[my][mx+i] = c.color(*distance_color(cell))
end
end
|
#draw_path(cell) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/amaze/formatter/ascii/delta.rb', line 68
def draw_path cell
x0, y0 = coord cell
mx = x0 + cell_size + 1
my = y0 + (cell_size + 1) / 2
char[my][mx] = center.color(path_color)
1.upto(cell_size) do |i|
char[my][mx+i] = h.color(path_color) if path?(:east, cell)
char[my+i][mx] = v.color(path_color) if path?(:south, cell)
end
end
|
#h ⇒ Object
104
105
106
|
# File 'lib/amaze/formatter/ascii/delta.rb', line 104
def h
'-'
end
|
#re ⇒ Object
Also known as:
nw
116
117
118
|
# File 'lib/amaze/formatter/ascii/delta.rb', line 116
def re
'/'
end
|
#rw ⇒ Object
Also known as:
ne
112
113
114
|
# File 'lib/amaze/formatter/ascii/delta.rb', line 112
def rw
'\\'
end
|
#v ⇒ Object
108
109
110
|
# File 'lib/amaze/formatter/ascii/delta.rb', line 108
def v
'|'
end
|
#xpos(column) ⇒ Object
88
89
90
|
# File 'lib/amaze/formatter/ascii/delta.rb', line 88
def xpos column
(cell_size + 1) * column
end
|
#ypos(row) ⇒ Object
92
93
94
|
# File 'lib/amaze/formatter/ascii/delta.rb', line 92
def ypos row
(cell_size + 1) * row
end
|