Class: RPiet::Image::Image
- Inherits:
-
Object
- Object
- RPiet::Image::Image
- Defined in:
- lib/rpiet/image/image.rb
Overview
Abstract base class for all image providers. Image providers only need to implement raw_pixel, raw_width, and raw_height.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#codel_size ⇒ Object
readonly
Returns the value of attribute codel_size.
Instance Method Summary collapse
- #ascii(group = []) ⇒ Object
- #color_for(rgb_hex) ⇒ Object
-
#initialize(codel_size) ⇒ Image
constructor
A new instance of Image.
- #pixel(x, y) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(codel_size) ⇒ Image
Returns a new instance of Image.
12 13 14 |
# File 'lib/rpiet/image/image.rb', line 12 def initialize(codel_size) @codel_size = codel_size end |
Instance Attribute Details
#codel_size ⇒ Object (readonly)
Returns the value of attribute codel_size.
10 11 12 |
# File 'lib/rpiet/image/image.rb', line 10 def codel_size @codel_size end |
Instance Method Details
#ascii(group = []) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rpiet/image/image.rb', line 25 def ascii(group = []) s = '' w, h = size h.times do |j| w.times do |i| value = pixel(i, j).to_initial s << (group.include?([i, j]) ? value.upcase : value) << ' ' end s << "\n" end s end |
#color_for(rgb_hex) ⇒ Object
21 22 23 |
# File 'lib/rpiet/image/image.rb', line 21 def color_for(rgb_hex) RPiet::Color::RGB[rgb_hex] end |
#pixel(x, y) ⇒ Object
16 17 18 19 |
# File 'lib/rpiet/image/image.rb', line 16 def pixel(x, y) r,g,b = raw_pixel(x * @codel_size, y * @codel_size) color_for(format "0x%02x%02x%02x" % [r,g,b]) end |
#size ⇒ Object
38 39 40 |
# File 'lib/rpiet/image/image.rb', line 38 def size [raw_width/@codel_size, raw_height/@codel_size] end |