Module: Fractals::Renderers::RMagickRenderer
- Defined in:
- lib/fractals/renderers.rb
Overview
Renders fractals using the RMagick library.
Instance Method Summary collapse
-
#to_blob(file_format) ⇒ Object
Returns the fractal image as a BLOB of the specified file format.
-
#write(file_path = 'fractal.png') ⇒ Object
Writes the image to the specified file path.
Instance Method Details
#to_blob(file_format) ⇒ Object
Returns the fractal image as a BLOB of the specified file format.
Example:
mandelbrot = Mandelbrot.new<br /> mandelbrot.renderer = Renderers::RMagickRenderer<br /> blob = mandelbrot.to_blob(‘jpg’)
129 130 131 132 133 134 135 136 |
# File 'lib/fractals/renderers.rb', line 129 def to_blob(file_format) image = Magick::Image.new(@width, @height) render do |x, y, color| image.pixel_color(x, y, "rgb(#{color.join(',')})") end image.to_blob { self.format = file_format; self.quality = 100 } end |
#write(file_path = 'fractal.png') ⇒ Object
Writes the image to the specified file path.
139 140 141 142 143 |
# File 'lib/fractals/renderers.rb', line 139 def write(file_path='fractal.png') File.open(file_path, 'wb') do |file| file.write(to_blob(file_path.split('.').last)) end end |