Skip to content

Instantly share code, notes, and snippets.

@ideamonk
Created October 24, 2010 19:55
Show Gist options
  • Save ideamonk/643917 to your computer and use it in GitHub Desktop.
Save ideamonk/643917 to your computer and use it in GitHub Desktop.
Q2. of BORQ
# Author: Abhishek Mishra <ideamonk@gmail.com>
require 'rubygems'
require 'choice'
Choice.options do
banner 'q2_lcd_numbers.rb [-shv] string'
separator 'Optional:'
option :size do
short '-s'
desc 'digit size'
cast Integer
default 1
end
separator 'Common:'
option :help do
short '-h'
long '--help'
desc 'Show this message.'
end
option :version do
short '-v'
long '--version'
desc 'Show version.'
action do
puts 'LCD generator 0.1'
exit
end
end
end
def paint_map(map,digit,size,start)
# upper, mid, bottom
for i in (start+1)...(start+size+1)
if $digits[digit][0] == 1
map[[0,i]] = 2
end
if $digits[digit][3] == 1
map[[0 + size + 1,i]] = 2
end
if $digits[digit][6] == 1
map[[0 + size*2 + 2,i]] = 2
end
end
# verticals
for i in 1...size+1
if $digits[digit][1] == 1
map[[i,0+start]] = 1
end
if $digits[digit][2] == 1
map[[i,size+1+start]] = 1
end
if $digits[digit][4] == 1
map[[i+size+1,0+start]] = 1
end
if $digits[digit][5] == 1
map[[i+size+1,size+1+start]] = 1
end
end
end
def print_map(map, size, total_digits)
for j in 0...(size*2+3)
for i in 0...(total_digits*(size+3))
if map[[j,i]] == 2
print '-'
elsif map[[j,i]] == 1
print '|'
else
print ' '
end
end
puts ''
end
end
def drive_paint(map, string, size)
i = 0
j = 0
while (i<string.size*(size+3))
paint_map(map,string[j..j].to_i,size,i)
i += size+3
j += 1
end
end
# _ 0
# | | 1 2
# - 3
# | | 4 5
# - 6
$digits = [
[1,1,1,0,1,1,1], [0,0,1,0,0,1,0], # 0 1
[1,0,1,1,1,0,1], [1,0,1,1,0,1,1], # 2 3
[0,1,1,1,0,1,0], [1,1,0,1,0,1,1], # 4 5
[1,1,0,1,1,1,1], [1,0,1,0,0,1,0], # 6 7
[1,1,1,1,1,1,1], [1,1,1,1,0,1,0], # 8 9
]
string = ARGV[-1]
size = Choice.choices[:size]
digitmap = {}
drive_paint(digitmap, string, size)
print_map(digitmap, size, string.size)
@ideamonk
Copy link
Author

ideamonk commented Nov 7, 2012

Not so happy to see this copy pasted in entirety by a dickhead I happened to meet super-briefly at a conference. http://d3cipher.wordpress.com/2011/02/25/borq-%E2%80%93-lcd-display/ . I guess I should add 'Author: ...' comments or copyright in every piece of code I put in public domain from now on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment