0
0
Fork 0

Be able to create an image from data

At the moment the image is simply shown to the user. But we need something
better. The user must be able to decide, what happens.
Also I want support for other colors.
This commit is contained in:
Stormwind 2015-02-18 23:45:53 +01:00
parent 992d738ede
commit 27b0a3dbda
2 changed files with 48 additions and 1 deletions

View File

@ -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

View File

@ -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