Module: Termdots

Defined in:
lib/termdots.rb,
lib/termdots/version.rb

Defined Under Namespace

Classes: ColorGenerator

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.get_elem_strObject



30
31
32
# File 'lib/termdots.rb', line 30

def get_elem_str
    return ELEM_STR
end

.mainObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/termdots.rb', line 34

def main
#          file_name = FILENAME.to_s
  puts 'Please enter a image path'
  file_name = gets.chomp.to_s
    if !File.exists?(file_name)
        puts "image file not found."
        exit
    end
    output_image(file_name)
end

.output_image(file_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/termdots.rb', line 11

def output_image(file_name)
    cg = ColorGenerator.new(COLOR_MODE)
    cg.set_transparent_color(0, 0, 0)

    img = ImageList.new(file_name)
    img = img.resize_to_fit(32, 32)
    for y in 0...img.rows
        for x in 0...img.columns
            src = img.pixel_color(x, y)
            r = src.red / 256
            g = src.green / 256
            b = src.blue / 256

            print cg.convert(r, g, b) + get_elem_str + cg.clear_color
        end
        puts ""
    end
end