Class: Amaze::Formatter::ASCII::Sigma
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
79
80
81
|
# File 'lib/amaze/formatter/ascii/sigma.rb', line 79
def char_array_height
ypos(grid.rows, true) + 1
end
|
#char_array_width ⇒ Object
75
76
77
|
# File 'lib/amaze/formatter/ascii/sigma.rb', line 75
def char_array_width
xpos(grid.columns) + cell_size
end
|
#coord(cell, ref = :topleft) ⇒ Object
56
57
58
59
60
61
62
63
64
|
# File 'lib/amaze/formatter/ascii/sigma.rb', line 56
def coord cell, ref=:topleft
x = xpos(cell.column)
y = ypos(cell.row, cell.column.odd?)
if ref == :center
x = x + cell_size * 3 / 2 + cell_size
y = y + cell_size
end
[x, y]
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
|
# File 'lib/amaze/formatter/ascii/sigma.rb', line 4
def draw_cell cell
x0, y0 = coord cell
x1 = x0 + cell_size
x2 = x0 + cell_size + cell_size * 3
y1 = y0 + cell_size
0.upto(cell_size*3-1) do |i|
char[y0][x1+i] = n.color(grid_color) unless cell.linked_to?(:north)
char[y0+cell_size*2][x1+i] = s.color(grid_color) unless cell.linked_to?(:south)
end
0.upto(cell_size-1) do |i|
char[y0+1+i][x2+i] = ne.color(grid_color) unless cell.linked_to?(:northeast)
char[y0+1+i][x0+cell_size-1-i] = nw.color(grid_color) unless cell.linked_to?(:northwest)
char[y1+1+i][x2+cell_size-1-i] = se.color(grid_color) unless cell.linked_to?(:southeast)
char[y1+1+i][x0+i] = sw.color(grid_color) unless cell.linked_to?(:southwest)
end
end
|
#draw_content(cell) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/amaze/formatter/ascii/sigma.rb', line 29
def draw_content cell
x, y = coord cell
distance(cell).center(cell_size * 3).chars.each_with_index do |c,i|
char[y+cell_size][x+cell_size+i] = c.color(*distance_color(cell))
end
end
|
#draw_path(cell) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/amaze/formatter/ascii/sigma.rb', line 36
def draw_path cell
x, y = coord cell, :center
1.upto(cell_size*2) do |i|
char[y+i][x] = p.color(path_color)
end if path?(:south, cell)
0.upto(cell_size-1) do |i|
char[y+i][x+i*4] = p.color(path_color)
char[y+i+1][x+i*4+2] = pnwse.color(path_color)
end if path?(:southeast, cell)
0.upto(cell_size-1) do |i|
char[y-i][x+i*4] = p.color(path_color)
char[y-i][x+i*4+2] = pswne.color(path_color)
end if path?(:northeast, cell)
char[y][x] = p.color(path_color)
end
|
#n ⇒ Object
Also known as:
s
83
84
85
|
# File 'lib/amaze/formatter/ascii/sigma.rb', line 83
def n
'_'
end
|
#ne ⇒ Object
Also known as:
sw
87
88
89
|
# File 'lib/amaze/formatter/ascii/sigma.rb', line 87
def ne
'\\'
end
|
#p ⇒ Object
95
96
97
|
# File 'lib/amaze/formatter/ascii/sigma.rb', line 95
def p
'.'
end
|
#pnwse ⇒ Object
99
100
101
|
# File 'lib/amaze/formatter/ascii/sigma.rb', line 99
def pnwse
'`'
end
|
#pswne ⇒ Object
103
104
105
|
# File 'lib/amaze/formatter/ascii/sigma.rb', line 103
def pswne
'ยด'
end
|
#se ⇒ Object
Also known as:
nw
91
92
93
|
# File 'lib/amaze/formatter/ascii/sigma.rb', line 91
def se
'/'
end
|
#xpos(column) ⇒ Object
66
67
68
|
# File 'lib/amaze/formatter/ascii/sigma.rb', line 66
def xpos column
(cell_size * 4) * column
end
|
#ypos(row, odd = false) ⇒ Object
70
71
72
73
|
# File 'lib/amaze/formatter/ascii/sigma.rb', line 70
def ypos row, odd=false
offset = odd ? cell_size : 0
(cell_size * 2) * row + offset
end
|