26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/bindot2braillegraph.rb', line 26
def self.convert(width, height, binary)
if width % 2 != 0 || height % 4 != 0
nil
else
table = []
vertical_char_num = height / 4
horizontal_char_num = width / 2
(0..(vertical_char_num - 1)).each do |v_pos|
row = []
(0..(horizontal_char_num - 1)).each do |h_pos|
braille_binary =
binary.slice((v_pos * 4 ) * width + h_pos * 2, 2) +
binary.slice((v_pos * 4 + 1) * width + h_pos * 2, 2) +
binary.slice((v_pos * 4 + 2) * width + h_pos * 2, 2) +
binary.slice((v_pos * 4 + 3) * width + h_pos * 2, 2)
row << @@num_to_braille_graph[braille_binary.to_i(2)]
end
table << row
end
table
end
end
|