Module: Fractals::Renderers::PNGRenderer

Defined in:
lib/fractals/renderers.rb

Overview

Renders fractals using the PNG library. PNGRenderer is the default renderer.

Instance Method Summary collapse

Instance Method Details

#to_blobObject

Returns the fractal image as a BLOB.



104
105
106
107
108
109
110
111
# File 'lib/fractals/renderers.rb', line 104

def to_blob()
  canvas = PNG::Canvas.new(@width, @height)
  render do |x, y, color|
    canvas[x, (y - @height).abs - 1] = PNG::Color.new(color[0], color[1], color[2], 255)
  end

  PNG.new(canvas).to_blob
end

#write(file_path = 'fractal.png') ⇒ Object

Writes the image to the specifiec file path.



114
115
116
# File 'lib/fractals/renderers.rb', line 114

def write(file_path='fractal.png')
  File.open(file_path, 'wb') { |file| file.write(to_blob) }
end