Class: Lorraine::Image
- Inherits:
-
Object
- Object
- Lorraine::Image
- Defined in:
- lib/lorraine/image.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#pixels ⇒ Object
Returns the value of attribute pixels.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
- #clear!(rgb, percent = true) ⇒ Object
- #count ⇒ Object
-
#initialize(w, h) ⇒ Image
constructor
A new instance of Image.
- #rgb_pixels(upper_limit = 1) ⇒ Object
-
#rgb_pixels=(rgb, percent = true) ⇒ Object
0.0 - 1.0.
- #rotate! ⇒ Object
Constructor Details
#initialize(w, h) ⇒ Image
Returns a new instance of Image.
26 27 28 29 |
# File 'lib/lorraine/image.rb', line 26 def initialize(w, h) self.width = w self.height = h end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
10 11 12 |
# File 'lib/lorraine/image.rb', line 10 def height @height end |
#pixels ⇒ Object
Returns the value of attribute pixels.
8 9 10 |
# File 'lib/lorraine/image.rb', line 8 def pixels @pixels end |
#width ⇒ Object
Returns the value of attribute width.
9 10 11 |
# File 'lib/lorraine/image.rb', line 9 def width @width end |
Class Method Details
.frames_between(a, b, steps = 10) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/lorraine/image.rb', line 12 def self.frames_between(a, b, steps = 10) raise "Different sized images for frames_between" if a.count != b.count pixel_frames = [] a.pixels.each_with_index do |a_px, i| b_px = b.pixels[i] pixel_frames << a_px.gradient_to(b_px, steps) end pixel_frames.transpose.map do |frame| img = Lorraine::Image.new(a.width, a.height) img.pixels = frame img end end |
Instance Method Details
#clear!(rgb, percent = true) ⇒ Object
40 41 42 43 44 |
# File 'lib/lorraine/image.rb', line 40 def clear!(rgb, percent = true) px = [] count.times{ px << Colorist::Color.from_rgb(rgb[0], rgb[1], rgb[2], percent: percent) } self.pixels = px end |
#count ⇒ Object
31 32 33 |
# File 'lib/lorraine/image.rb', line 31 def count self.width * self.height end |
#rgb_pixels(upper_limit = 1) ⇒ Object
50 51 52 |
# File 'lib/lorraine/image.rb', line 50 def rgb_pixels(upper_limit = 1) self.pixels.map {|px| [px.r.to_f / 255.0 * upper_limit, px.g.to_f / 255.0 * upper_limit, px.b.to_f / 255.0 * upper_limit] } end |
#rgb_pixels=(rgb, percent = true) ⇒ Object
0.0 - 1.0
36 37 38 |
# File 'lib/lorraine/image.rb', line 36 def rgb_pixels=(rgb, percent = true) self.pixels = rgb.map{ |px| Colorist::Color.from_rgb(px[0], px[1], px[2], percent: percent) } end |
#rotate! ⇒ Object
46 47 48 |
# File 'lib/lorraine/image.rb', line 46 def rotate! @pixels.rotate! end |