Class: Theseus::Formatters::PNG::Orthogonal
- Inherits:
-
Theseus::Formatters::PNG
- Object
- Theseus::Formatters::PNG
- Theseus::Formatters::PNG::Orthogonal
- Defined in:
- lib/theseus/formatters/png/orthogonal.rb
Overview
Renders an OrthogonalMaze to a PNG canvas.
You will almost never access this class directly. Instead, use OrthogonalMaze#to(:png, options) to return the raw PNG data directly.
Constant Summary
Constants inherited from Theseus::Formatters::PNG
ANY_E, ANY_N, ANY_S, ANY_W, DEFAULTS
Instance Attribute Summary
Attributes inherited from Theseus::Formatters::PNG
Instance Method Summary collapse
-
#initialize(maze, options = {}) ⇒ Orthogonal
constructor
Create and return a fully initialized PNG::Orthogonal object, with the maze rendered.
Methods inherited from Theseus::Formatters::PNG
#clamp, #color_at, #fill_poly, #fill_rect, #line, #move, #to_blob
Constructor Details
#initialize(maze, options = {}) ⇒ Orthogonal
Create and return a fully initialized PNG::Orthogonal object, with the maze rendered. To get the maze data, call #to_blob.
See Theseus::Formatters::PNG for a list of all supported options.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/theseus/formatters/png/orthogonal.rb', line 15 def initialize(maze, ={}) super width = [:outer_padding] * 2 + maze.width * [:cell_size] height = [:outer_padding] * 2 + maze.height * [:cell_size] canvas = ChunkyPNG::Image.new(width, height, [:background]) @d1 = [:cell_padding] @d2 = [:cell_size] - [:cell_padding] @w1 = ([:wall_width] / 2.0).floor @w2 = (([:wall_width] - 1) / 2.0).floor maze.height.times do |y| py = [:outer_padding] + y * [:cell_size] maze.width.times do |x| px = [:outer_padding] + x * [:cell_size] draw_cell(canvas, [x, y], px, py, maze[x, y]) end end @blob = canvas.to_blob end |