Class: Amaze::Formatter::ASCII::Upsilon

Inherits:
Amaze::Formatter::ASCII show all
Defined in:
lib/amaze/formatter/ascii/upsilon.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

#centerObject



186
187
188
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 186

def center
  ''
end

#char_array_heightObject



149
150
151
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 149

def char_array_height
  y(grid.rows) + cell_size + 2
end

#char_array_widthObject



145
146
147
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 145

def char_array_width
  x(grid.columns) + cell_size + 2
end

#coord(cell) ⇒ Object

left, right, top, bottom



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 123

def coord cell
  x0 = x(cell.column)
  x1 = x0 + cell_size + 1
  x2 = x1 + cell_size * 3 + 1
  x3 = x2 + cell_size + 1
  y0 = y(cell.row)
  y1 = y0 + cell_size + 1
  y2 = y1 + cell_size + 1
  y3 = y2 + cell_size + 1
  [x0, x1, x2, x3, y0, y1, y2, y3]
end

#cornerObject



190
191
192
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 190

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 4

def draw_cell cell
  x0, x1, x2, x3, y0, y1, y2, y3 = coord cell
  
  if (cell.row+cell.column).even?
    # draw octo cell
    # corners
    char[y0][x1] = corner.color(grid_color)
    char[y0][x2] = corner.color(grid_color)
    char[y1][x0] = corner.color(grid_color)
    char[y1][x3] = corner.color(grid_color)
    char[y2][x0] = corner.color(grid_color)
    char[y2][x3] = corner.color(grid_color)
    char[y3][x1] = corner.color(grid_color)
    char[y3][x2] = corner.color(grid_color)
    1.upto(cell_size) do |i|
      # northeast
      char[y0+i][x2+i] = ne.color(grid_color) unless cell.linked_to?(:northeast)
      # southeast
      char[y2+i][x3-i] = se.color(grid_color) unless cell.linked_to?(:southeast)
      # southwest
      char[y2+i][x0+i] = sw.color(grid_color) unless cell.linked_to?(:southwest)
      # northwest
      char[y0+i][x1-i] = nw.color(grid_color) unless cell.linked_to?(:northwest)
      # east
      char[y1+i][x3] = v.color(grid_color) unless cell.linked_to?(:east)
      # west
      char[y1+i][x0] = v.color(grid_color) unless cell.linked_to?(:west)
    end
    1.upto(cell_size*3) do |i|
      # north
      char[y0][x1+i] = h.color(grid_color) unless cell.linked_to?(:north)
      # south
      char[y3][x1+i] = h.color(grid_color) unless cell.linked_to?(:south)
    end
  else
    # draw square cell
    # corners
    char[y1][x1] = corner.color(grid_color)
    char[y1][x2] = corner.color(grid_color)
    char[y2][x1] = corner.color(grid_color)
    char[y2][x2] = corner.color(grid_color)
    1.upto(cell_size) do |i|
      # east
      char[y1+i][x2] = v.color(grid_color) unless cell.linked_to?(:east)
      # west
      char[y1+i][x1] = v.color(grid_color) unless cell.linked_to?(:west)
    end
    1.upto(cell_size*3) do |i|
      # north
      char[y1][x1+i] = h.color(grid_color) unless cell.linked_to?(:north)
      # south
      char[y2][x1+i] = h.color(grid_color) unless cell.linked_to?(:south)
    end
  end
end

#draw_content(cell) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 60

def draw_content cell
  x0, x1, x2, x3, y0, y1, y2, y3 = coord cell
  
  y = y1 + (y2 - y1) / 2
  distance(cell).center(cell_size * 3).chars.each_with_index do |c,i|
    char[y][x1+1+i] = c.color(*distance_color(cell))
  end
end

#draw_path(cell) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 69

def draw_path cell
  x0, x1, x2, x3, y0, y1, y2, y3 = coord cell
  
  # middle of cell
  mx0 = (x1 + x2) / 2
  my0 = (y1 + y2) / 2
  
  # delta to middle of neighbor cell
  dx = cell_size * 4 + 2
  dy = cell_size * 2 + 2
  
  # north-south
  1.upto(dy-1) do |i|
    char[my0+i][mx0] = v.color(path_color)
  end if path?(:south, cell)
  # west-east
  1.upto(dx-1) do |i|
    char[my0][mx0+i] = h.color(path_color)
  end if path?(:east, cell)
  
  if (cell.column+cell.row).even?
    # northwest-southeast
    if path?(:southeast, cell)
      mx1 = mx0 + dx / 2
      my1 = my0 + dy / 2

      char[my1][mx1] = center.color(path_color)
      1.upto(cell_size) do |i|
        char[my0+i][mx0+i*2-1] = pnwse1.color(path_color)
        char[my0+i][mx0+i*2] = pnwse2.color(path_color)
        char[my1+i][mx1+i*2-1] = pnwse1.color(path_color)
        char[my1+i][mx1+i*2] = pnwse2.color(path_color)
      end
    end
    # northeast-southwest
    if path?(:southwest, cell)
      mx1 = mx0 - dx / 2
      my1 = my0 + dy / 2

      char[my1][mx1] = center.color(path_color)
      1.upto(cell_size) do |i|
        char[my0+i][mx0-i*2+1] = pswne1.color(path_color)
        char[my0+i][mx0-i*2] = pswne2.color(path_color)
        char[my1+i][mx1-i*2+1] = pswne1.color(path_color)
        char[my1+i][mx1-i*2] = pswne2.color(path_color)
      end
    end
  end

  # center
  char[my0][mx0] = center.color(path_color)
end

#hObject



153
154
155
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 153

def h
  '-'
end

#neObject Also known as: sw



161
162
163
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 161

def ne
  '\\'
end

#pnwse1Object



172
173
174
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 172

def pnwse1
  '`'
end

#pnwse2Object Also known as: pswne2



176
177
178
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 176

def pnwse2
  '.'
end

#pswne1Object



180
181
182
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 180

def pswne1
  '´'
end

#seObject Also known as: nw



165
166
167
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 165

def se
  '/'
end

#vObject



157
158
159
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 157

def v
  '|'
end

#x(column) ⇒ Object



135
136
137
138
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 135

def x column
  # x0 for octo cell
  (cell_size * 4 + 2) * column
end

#y(row) ⇒ Object



140
141
142
143
# File 'lib/amaze/formatter/ascii/upsilon.rb', line 140

def y row
  # y0 for octo cell
  (cell_size * 2 + 2) * row
end