Class: Theseus::Formatters::PNG::Delta
- Inherits:
-
Theseus::Formatters::PNG
- Object
- Theseus::Formatters::PNG
- Theseus::Formatters::PNG::Delta
- Defined in:
- lib/theseus/formatters/png/delta.rb
Overview
Renders a DeltaMaze to a PNG canvas. Does not currently support the :wall_width option.
You will almost never access this class directly. Instead, use DeltaMaze#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 = {}) ⇒ Delta
constructor
Create and return a fully initialized PNG::Delta 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 = {}) ⇒ Delta
Create and return a fully initialized PNG::Delta object, with the maze rendered. To get the maze data, call #to_blob.
See Theseus::Formatters::PNG for a list of all supported options.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/theseus/formatters/png/delta.rb', line 16 def initialize(maze, ={}) super height = [:outer_padding] * 2 + maze.height * [:cell_size] width = [:outer_padding] * 2 + (maze.width + 1) * [:cell_size] / 2 canvas = ChunkyPNG::Image.new(width, height, [:background]) maze.height.times do |y| py = [:outer_padding] + y * [:cell_size] maze.row_length(y).times do |x| px = [:outer_padding] + x * [:cell_size] / 2.0 draw_cell(canvas, [x, y], maze.points_up?(x,y), px, py, maze[x, y]) end end @blob = canvas.to_blob end |