0
0
Fork 0

Improvement of Rubella::Output::Image

The class now overwrites the constructor of the basic class to set a default
field_size value of 15 pixels.
It also returns self in the create method corresponding to the base class.
Plus I've added the documentation.
This commit is contained in:
Stormwind 2015-02-24 20:57:56 +01:00
parent e6922a81a5
commit f5efd50d9f
2 changed files with 26 additions and 3 deletions

View File

@ -17,6 +17,7 @@ module Rubella
#
# @param field_size int size of one value
# @return Rubella::Output::Base
#
def initialize field_size
@field_size = field_size
end
@ -26,6 +27,7 @@ module Rubella
#
# @param storage Rubella::Storage
# @return Rubella::Output::Base
#
def create storage
raise NotImplementedError "Please override 'create' in your concrete "+
"implementation"

View File

@ -4,8 +4,29 @@ require 'RMagick'
module Rubella
module Output
# Creates a pixel based graphic as representation of the given storage
# data using ImageMagick.
# By the RMagick extention. @data will contain a Magick image for futher
# handling the data please read the RMagick library documentation:
# http://www.imagemagick.org/RMagick/doc/
#
class Image < Base
# Constructor
# Has a default field_size of 15 pixel.
#
# @param field_size int How many pixel one value has
# @return Rubella::Output::Image
#
def initialize field_size = 15
super field_size
end
# Creates a pixel based graphic from the given storage data.
#
# @param storage Rubella::Storage
# @return Rubella::Output::Image
#
def create storage
buckets = storage.data[0].length
columns = storage.data.length
@ -15,7 +36,7 @@ module Rubella
y = buckets*@field_size
# start drawing the damn thing
loadImg = Magick::Image.new(x, y) { self.background_color = "white" }
@data = Magick::Image.new(x, y) { self.background_color = "white" }
i = 0
storage.data.each do |point|
@ -34,13 +55,13 @@ module Rubella
# 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
core.draw @data
j = j + 1
end
i = i + 1
end
@data = loadImg
self
end