# Segment naming: Or bitmasks:
# 0 01
# 1 2 02 04
# 3 08
# 4 5 10 20
# 6 40
# 0 1 2 3 4 5 6 7 8 9 : .
digits = [0x77,0x24,0x5D,0x6D,0x2E, 0x6B,0x7B,0x27,0x7F,0x6F, 0x80,0x100]
# Rendering of the individual cell:
$digit=[
[0x00,0x03,0x01,0x01,0x01,0x05,0x00], # 31115
[0x02,0x02,0x00,0x00,0x00,0x04,0x04], # 22 44
[0x02,0x02,0x00,0x80,0x00,0x04,0x04], # 22 44
[0x00,0x1A,0x08,0x08,0x08,0x2C,0x00], # K888M
[0x10,0x10,0x00,0x00,0x00,0x20,0x20], # 11 22
[0x10,0x10,0x00,0x180,0x0,0x20,0x20], # 11 22
[0x00,0x50,0x40,0x40,0x40,0x60,0x00] # 54446
]
def render_digit(x,y, whichbits)
$digit.each do |line|
$stdout.putc 27
$stdout.print "[#{y};#{x}H"
line.each do |cell|
if (cell&whichbits) != 0 then
$stdout.putc 27
$stdout.print "[1;37m#"
elsif cell != 0 then
$stdout.putc 27
$stdout.print "[0;34m."
else
$stdout.putc " "
end
end
y=y+1
$stdout.putc 10
end
end
$stdout.putc 27
$stdout.print "[2J\n"
$last={}
while now = Time.now
clock = [ now.hour / 10, now.hour % 10, 10,
now.min / 10, now.min % 10, 10,
now.sec / 10, now.sec % 10, 11,
now.usec / 100000]
x,y = 5,3
clock.each do |digit|
render_digit x,y, $last[x] = digits[digit] unless $last[x] == digits[digit]
x=x+8
end
Kernel.sleep 0.1
end