Class: Amaze::Formatter::Image::Ortho
Instance Attribute Summary
#grid, #options
Instance Method Summary
collapse
#background_color, #border_width, #canvas, #cell_offset, #cell_width, colors, #distance_color, #distances, #distances_max, #gradient, #hide_walls?, #image, #initialize, #path?, #path_cell?, #path_cells, #path_color, #path_finish, #path_start, #path_width, #render, #show_grid?, #wall_color, #wall_width, #write
Instance Method Details
#center_coord(cell) ⇒ Object
87
88
89
90
91
92
93
94
|
# File 'lib/amaze/formatter/image/ortho.rb', line 87
def center_coord cell
row, column = cell.row, cell.column
x = (column+0.5) * cell_width + cell_offset
y = (row+0.5) * cell_width + cell_offset
[x, y]
end
|
#coord(cell) ⇒ Object
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/amaze/formatter/image/ortho.rb', line 76
def coord cell
row, column = cell.row, cell.column
x1 = column * cell_width + cell_offset
x2 = (column+1) * cell_width + cell_offset
y1 = row * cell_width + cell_offset
y2 = (row+1) * cell_width + cell_offset
[x1, x2, y1, y2]
end
|
#image_height ⇒ Object
100
101
102
|
# File 'lib/amaze/formatter/image/ortho.rb', line 100
def image_height
cell_width * grid.rows + wall_width + border_width * 2 + 1
end
|
#image_width ⇒ Object
96
97
98
|
# File 'lib/amaze/formatter/image/ortho.rb', line 96
def image_width
cell_width * grid.columns + wall_width + border_width * 2 + 1
end
|
#render_background ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/amaze/formatter/image/ortho.rb', line 4
def render_background
canvas.stroke_antialias true
canvas.stroke_linecap 'square'
canvas.stroke 'none'
grid.each_cell do |cell|
color = distance_color cell
next unless color
canvas.fill color
x1, x2, y1, y2 = coord cell
canvas.polygon x1, y1, x2, y1, x2, y2, x1, y2
end
end
|
#render_grid ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/amaze/formatter/image/ortho.rb', line 17
def render_grid
canvas.stroke_antialias true
canvas.stroke_linecap 'square'
canvas.stroke 'gray90'
canvas.stroke_width 1
canvas.fill 'none'
grid.each_cell do |cell|
x1, x2, y1, y2 = coord cell
canvas.polygon x1, y1, x2, y1, x2, y2, x1, y2
end
end
|
#render_path ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/amaze/formatter/image/ortho.rb', line 47
def render_path
canvas.stroke_antialias true
canvas.stroke_linecap 'square'
canvas.fill 'none'
canvas.stroke path_color
canvas.stroke_width path_width
grid.each_cell do |cell|
next unless path_cell? cell
x1, y1 = center_coord cell
%i( north east ).each do |direction|
next unless path?(direction, cell)
x2, y2 = center_coord cell.send(direction)
canvas.line x1, y1, x2, y2
end
end
canvas.stroke_antialias true
canvas.stroke_linecap 'square'
canvas.fill path_color
canvas.stroke 'none'
[path_start, path_finish].compact.each do |cell|
x, y = center_coord cell
canvas.ellipse x, y, path_width*2, path_width*2, 0, 360
end
end
|
#render_wall ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/amaze/formatter/image/ortho.rb', line 30
def render_wall
canvas.stroke_antialias true
canvas.stroke_linecap 'square'
canvas.stroke wall_color
canvas.stroke_width wall_width
canvas.fill 'none'
grid.each_cell do |cell|
x1, x2, y1, y2 = coord cell
canvas.line x1, y1, x2, y1 unless cell.linked_to?(:north)
canvas.line x2, y1, x2, y2 unless cell.linked_to?(:east)
canvas.line x1, y2, x2, y2 unless cell.linked_to?(:south)
canvas.line x1, y1, x1, y2 unless cell.linked_to?(:west)
end
end
|