Class: Amaze::Formatter::ASCII::Sigma

Inherits:
Amaze::Formatter::ASCII show all
Defined in:
lib/amaze/formatter/ascii/sigma.rb

Instance Attribute Summary

Attributes inherited from Amaze::Formatter::ASCII

#grid, #options

Instance Method Summary collapse

Methods inherited from Amaze::Formatter::ASCII

#ansi_clear, #cell_size, #char, #clear, #distance, #distance_color, #distances, #grid_color, #initialize, #path?, #path_cell?, #path_color, #render

Constructor Details

This class inherits a constructor from Amaze::Formatter::ASCII

Instance Method Details

#char_array_heightObject



79
80
81
# File 'lib/amaze/formatter/ascii/sigma.rb', line 79

def char_array_height
  ypos(grid.rows, true) + 1
end

#char_array_widthObject



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|
    # north
    char[y0][x1+i] = n.color(grid_color) unless cell.linked_to?(:north)
    # south
    char[y0+cell_size*2][x1+i] = s.color(grid_color) unless cell.linked_to?(:south)
  end

  0.upto(cell_size-1) do |i|
    # north east
    char[y0+1+i][x2+i] = ne.color(grid_color) unless cell.linked_to?(:northeast)
    # north west
    char[y0+1+i][x0+cell_size-1-i] = nw.color(grid_color) unless cell.linked_to?(:northwest)
    # south east
    char[y1+1+i][x2+cell_size-1-i] = se.color(grid_color) unless cell.linked_to?(:southeast)
    # south west
    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
  # north-south
  1.upto(cell_size*2) do |i|
    char[y+i][x] = p.color(path_color)
  end if path?(:south, cell)
  # northwest-southeast
  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)
  # southwest-northeast
  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)
  # center
  char[y][x] = p.color(path_color)
end

#nObject Also known as: s



83
84
85
# File 'lib/amaze/formatter/ascii/sigma.rb', line 83

def n
  '_'
end

#neObject Also known as: sw



87
88
89
# File 'lib/amaze/formatter/ascii/sigma.rb', line 87

def ne
  '\\'
end

#pObject



95
96
97
# File 'lib/amaze/formatter/ascii/sigma.rb', line 95

def p
  '.'
end

#pnwseObject



99
100
101
# File 'lib/amaze/formatter/ascii/sigma.rb', line 99

def pnwse
  '`'
end

#pswneObject



103
104
105
# File 'lib/amaze/formatter/ascii/sigma.rb', line 103

def pswne
  'ยด'
end

#seObject 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