Class: Amaze::Formatter::Image
- Inherits:
-
Object
- Object
- Amaze::Formatter::Image
show all
- Defined in:
- lib/amaze/formatter/image.rb
Defined Under Namespace
Classes: Delta, Ortho, Polar, Sigma, Upsilon
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(grid, options = {}) ⇒ Image
Returns a new instance of Image.
17
18
19
20
|
# File 'lib/amaze/formatter/image.rb', line 17
def initialize grid, options={}
@grid = grid
@options = options
end
|
Instance Attribute Details
#grid ⇒ Object
12
13
14
|
# File 'lib/amaze/formatter/image.rb', line 12
def grid
@grid
end
|
#options ⇒ Object
Options for the Image renderer
15
16
17
|
# File 'lib/amaze/formatter/image.rb', line 15
def options
@options
end
|
Class Method Details
.colors ⇒ Object
124
125
126
|
# File 'lib/amaze/formatter/image.rb', line 124
def self.colors
Magick.colors.map(&:name)
end
|
Instance Method Details
#background_color ⇒ Object
86
87
88
|
# File 'lib/amaze/formatter/image.rb', line 86
def background_color
@options[:background_color].to_s || 'white'
end
|
#border_width ⇒ Object
66
67
68
|
# File 'lib/amaze/formatter/image.rb', line 66
def border_width
@options[:border_width] || 0
end
|
#canvas ⇒ Object
53
54
55
|
# File 'lib/amaze/formatter/image.rb', line 53
def canvas
@canvas ||= Magick::Draw.new
end
|
#cell_offset ⇒ Object
98
99
100
|
# File 'lib/amaze/formatter/image.rb', line 98
def cell_offset
wall_width / 2.0 + border_width
end
|
#cell_width ⇒ Object
62
63
64
|
# File 'lib/amaze/formatter/image.rb', line 62
def cell_width
@options[:cell_width] || 100
end
|
#distance_color(cell) ⇒ Object
Returns the background color of a cell, depending on its distance from the origin
111
112
113
114
115
116
117
118
|
# File 'lib/amaze/formatter/image.rb', line 111
def distance_color cell
if distances && distances[cell]
intensity = (distances_max - distances[cell].to_f) / distances_max
'#' + gradient.at(intensity).color.hex
else
nil
end
end
|
#distances ⇒ Object
102
103
104
|
# File 'lib/amaze/formatter/image.rb', line 102
def distances
options[:distances]
end
|
#distances_max ⇒ Object
106
107
108
|
# File 'lib/amaze/formatter/image.rb', line 106
def distances_max
@distances_max ||= distances.max[1]
end
|
#gradient ⇒ Object
120
121
122
|
# File 'lib/amaze/formatter/image.rb', line 120
def gradient
options[:gradient_map]
end
|
#hide_walls? ⇒ Boolean
94
95
96
|
# File 'lib/amaze/formatter/image.rb', line 94
def hide_walls?
@options[:hide_walls]
end
|
#image ⇒ Object
49
50
51
|
# File 'lib/amaze/formatter/image.rb', line 49
def image
@image ||= Magick::Image.new image_width, image_height, Magick::SolidFill.new(background_color)
end
|
#path?(direction, cell) ⇒ Boolean
22
23
24
|
# File 'lib/amaze/formatter/image.rb', line 22
def path? direction, cell
cell.linked?(cell.send(direction)) && path_cell?(cell.send(direction))
end
|
#path_cell?(cell) ⇒ Boolean
26
27
28
|
# File 'lib/amaze/formatter/image.rb', line 26
def path_cell? cell
path_cells.include? cell
end
|
#path_cells ⇒ Object
30
31
32
|
# File 'lib/amaze/formatter/image.rb', line 30
def path_cells
Array(options[:path_cells])
end
|
#path_color ⇒ Object
82
83
84
|
# File 'lib/amaze/formatter/image.rb', line 82
def path_color
@options[:path_color].to_s || 'red'
end
|
#path_finish ⇒ Object
38
39
40
|
# File 'lib/amaze/formatter/image.rb', line 38
def path_finish
options[:path_finish]
end
|
#path_start ⇒ Object
34
35
36
|
# File 'lib/amaze/formatter/image.rb', line 34
def path_start
options[:path_start]
end
|
#path_width ⇒ Object
78
79
80
|
# File 'lib/amaze/formatter/image.rb', line 78
def path_width
@options[:path_width] || 3
end
|
#render ⇒ Object
42
43
44
45
46
47
|
# File 'lib/amaze/formatter/image.rb', line 42
def render
render_background if distances
render_grid if show_grid?
render_wall unless hide_walls?
render_path if path_cells.any?
end
|
#show_grid? ⇒ Boolean
90
91
92
|
# File 'lib/amaze/formatter/image.rb', line 90
def show_grid?
@options[:show_grid]
end
|
#wall_color ⇒ Object
74
75
76
|
# File 'lib/amaze/formatter/image.rb', line 74
def wall_color
@options[:wall_color].to_s || 'black'
end
|
#wall_width ⇒ Object
70
71
72
|
# File 'lib/amaze/formatter/image.rb', line 70
def wall_width
@options[:wall_width] || 5
end
|
#write(filename) ⇒ Object
57
58
59
60
|
# File 'lib/amaze/formatter/image.rb', line 57
def write filename
canvas.draw image
image.write(filename)
end
|