Class: RPiet::Image::AsciiImage
- Defined in:
- lib/rpiet/image/ascii_image.rb
Constant Summary collapse
- STR2RGB =
{ 'lr' => [0xff, 0xc0, 0xc0], 'ly' => [0xff, 0xff, 0xc0], 'lg' => [0xc0, 0xff, 0xc0], 'lc' => [0xc0, 0xff, 0xff], 'lb' => [0xc0, 0xc0, 0xff], 'lm' => [0xff, 0xc0, 0xff], 'nr' => [0xff, 0x00, 0x00], 'ny' => [0xff, 0xff, 0x00], 'ng' => [0xc0, 0xff, 0x00], 'nc' => [0x00, 0xff, 0xff], 'nb' => [0x00, 0x00, 0xff], 'nm' => [0xff, 0x00, 0xff], 'dr' => [0xc0, 0x00, 0x00], 'dy' => [0xc0, 0xc0, 0x00], 'dg' => [0x00, 0xc0, 0x00], 'dc' => [0x00, 0xc0, 0xc0], 'db' => [0x00, 0x00, 0xc0], 'dm' => [0xc0, 0x00, 0xc0], '..' => [0xff, 0xff, 0xff], '++' => [0x00, 0x00, 0x00] }
Instance Attribute Summary
Attributes inherited from Image
Instance Method Summary collapse
-
#initialize(string, codel_size = 1) ⇒ AsciiImage
constructor
A new instance of AsciiImage.
- #raw_height ⇒ Object
- #raw_pixel(x, y) ⇒ Object
- #raw_width ⇒ Object
- #str_to_rgb(str) ⇒ Object
Methods inherited from Image
#ascii, #color_for, #pixel, #size
Constructor Details
#initialize(string, codel_size = 1) ⇒ AsciiImage
Returns a new instance of AsciiImage.
6 7 8 9 10 11 12 13 |
# File 'lib/rpiet/image/ascii_image.rb', line 6 def initialize(string, codel_size=1) @codel_size = codel_size lines = string.split("\n") @data = [] lines.each do |line| @data << line.split(/\s+/).map { |e| str_to_rgb(e) } end end |
Instance Method Details
#raw_height ⇒ Object
19 20 21 |
# File 'lib/rpiet/image/ascii_image.rb', line 19 def raw_height @data.length end |
#raw_pixel(x, y) ⇒ Object
15 16 17 |
# File 'lib/rpiet/image/ascii_image.rb', line 15 def raw_pixel(x, y) @data[x][y] end |
#raw_width ⇒ Object
23 24 25 |
# File 'lib/rpiet/image/ascii_image.rb', line 23 def raw_width @data[0].length end |
#str_to_rgb(str) ⇒ Object
50 51 52 |
# File 'lib/rpiet/image/ascii_image.rb', line 50 def str_to_rgb(str) STR2RGB[str] end |