class Phlox::Graphics
Public Class Methods
new(width=255, height=255)
click to toggle source
# File lib/phlox/graphics.rb, line 5 def initialize(width=255, height=255) @width, @height = width, height @img = Magick::Image.new @width, @height end
Public Instance Methods
fill(grad_prc)
click to toggle source
Fill the image with a pixel gradient determined by the proc argument. The proc should yield a 3-element list of [r, g, b] values for each location.
# File lib/phlox/graphics.rb, line 12 def fill grad_prc # make an array to hold the values data = Array.new(@width) do |x| Array.new(@height) do |y| grad_prc.call x, y end end # write the color values into the image data.each_with_index do |row, y| row.each_with_index do |val, x| @img.pixel_color y, x, "rgb(#{val.join ', '})" end end end
write(path, scale=1)
click to toggle source
Write the image file to `path` with optional scaling.
# File lib/phlox/graphics.rb, line 29 def write path, scale=1 @img.scale(scale).write path end