Module: XbmRuby

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

Overview

:nodoc:

Defined Under Namespace

Modules: VERSION

Constant Summary collapse

BITS =
{ 
  "0" => %w[0x00 0x1c 0x22 0x22 0x22 0x22 0x22 0x1c],
  "1" => %w[0x08 0x0c 0x0a 0x08 0x08 0x08 0x08 0x3e],
  "2" => %w[0x1c 0x22 0x20 0x10 0x08 0x04 0x02 0x3e],
  "3" => %w[0x3e 0x10 0x08 0x1c 0x20 0x20 0x20 0x1e],
  "4" => %w[0x30 0x28 0x24 0x24 0x7c 0x20 0x20 0x20],
  "5" => %w[0x3c 0x04 0x04 0x1c 0x20 0x20 0x20 0x1c],
  "6" => %w[0x38 0x44 0x04 0x3c 0x44 0x44 0x44 0x38],
  "7" => %w[0x3e 0x22 0x20 0x10 0x10 0x08 0x08 0x08],
  "8" => %w[0x00 0x1c 0x22 0x22 0x1c 0x22 0x22 0x1c],
  "9" => %w[0x00 0x1c 0x22 0x22 0x3c 0x20 0x10 0x0c]
}

Instance Method Summary collapse

Instance Method Details

#build_bitmap(number) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/xbm_ruby.rb', line 15

def build_bitmap(number)
  array = number.to_s.split(//).map { |n| n.to_i }.reverse
  
  bits = StringIO.new
  bits.write "#define counter_width #{8 * array.size}\n"
  bits.write "#define counter_height 8\n"
  bits.write "static char number_bits[] = {\n"
  
  0.upto(7) do |i|
    (array.size - 1).downto(0) do |j|
      bits.write sprintf("0x%02x,", get_bit_value(array[j], i));
    end
  end
  
  bits.write " };"
  bits.string
end

#get_bit_value(num, el) ⇒ Object



33
34
35
# File 'lib/xbm_ruby.rb', line 33

def get_bit_value(num, el)
  BITS[num.to_s][el]
end