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:
parent
e6922a81a5
commit
f5efd50d9f
|
@ -17,6 +17,7 @@ module Rubella
|
||||||
#
|
#
|
||||||
# @param field_size int size of one value
|
# @param field_size int size of one value
|
||||||
# @return Rubella::Output::Base
|
# @return Rubella::Output::Base
|
||||||
|
#
|
||||||
def initialize field_size
|
def initialize field_size
|
||||||
@field_size = field_size
|
@field_size = field_size
|
||||||
end
|
end
|
||||||
|
@ -26,6 +27,7 @@ module Rubella
|
||||||
#
|
#
|
||||||
# @param storage Rubella::Storage
|
# @param storage Rubella::Storage
|
||||||
# @return Rubella::Output::Base
|
# @return Rubella::Output::Base
|
||||||
|
#
|
||||||
def create storage
|
def create storage
|
||||||
raise NotImplementedError "Please override 'create' in your concrete "+
|
raise NotImplementedError "Please override 'create' in your concrete "+
|
||||||
"implementation"
|
"implementation"
|
||||||
|
|
|
@ -4,8 +4,29 @@ require 'RMagick'
|
||||||
module Rubella
|
module Rubella
|
||||||
module Output
|
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
|
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
|
def create storage
|
||||||
buckets = storage.data[0].length
|
buckets = storage.data[0].length
|
||||||
columns = storage.data.length
|
columns = storage.data.length
|
||||||
|
@ -15,7 +36,7 @@ module Rubella
|
||||||
y = buckets*@field_size
|
y = buckets*@field_size
|
||||||
|
|
||||||
# start drawing the damn thing
|
# 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
|
i = 0
|
||||||
storage.data.each do |point|
|
storage.data.each do |point|
|
||||||
|
@ -34,13 +55,13 @@ module Rubella
|
||||||
# Draw
|
# Draw
|
||||||
core.fill(Magick::Pixel.from_hsla(0, 255, l, 1).to_color)
|
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.rectangle((i*@field_size), (j*@field_size), ((i+1)*@field_size), ((j+1)*@field_size))
|
||||||
core.draw loadImg
|
core.draw @data
|
||||||
j = j + 1
|
j = j + 1
|
||||||
end
|
end
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@data = loadImg
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue