Class: RPiet::Image::AsciiImage

Inherits:
Image
  • Object
show all
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

#codel_size

Instance Method Summary collapse

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_heightObject



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_widthObject



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