diff --git a/lib/rubella.rb b/lib/rubella.rb index 4c26ef1..d290f0e 100644 --- a/lib/rubella.rb +++ b/lib/rubella.rb @@ -56,7 +56,8 @@ module Rubella def process inpt weight = @weighting.new 10 - weight.parse inpt + outpt = @output.new + outpt.create weight.parse(inpt) end def input_json diff --git a/lib/rubella/output/image.rb b/lib/rubella/output/image.rb index aa09a4b..cbae72a 100644 --- a/lib/rubella/output/image.rb +++ b/lib/rubella/output/image.rb @@ -1,7 +1,53 @@ +require 'RMagick' + module Rubella module Output class Image + attr_accessor :field_size + + def initialize field_size = 15 + @field_size = field_size + end + + def create parsed_list + buckets = parsed_list[0].length + columns = parsed_list.length + + # image size + x = columns*@field_size + y = buckets*@field_size + + # start drawing the damn thing + loadImg = Magick::Image.new(x, y) { self.background_color = "white" } + + i = 0 + parsed_list.each do |point| + j = 0 + point.reverse.each do |part| + # draw a red rectangle on the white background + core = Magick::Draw.new + + idensity = 127.5 * part + # Fix for float stupidity + idensity = 127.5 if idensity > 127.5 + + # Get the correct value + l = (255-idensity).round + + # Draw + core.fill(Magick::Pixel.from_hsla(0, 255, l, 1).to_color) + core.rectangle((i*@field_size), (j*@field_size), ((i+1)*@field_size), ((j+1)*@field_size)) + core.draw loadImg + j = j + 1 + end + i = i + 1 + end + + loadImg.display + end + + end end