This does a one-time printing job for the current time.my $time = sprintf '%02d0%02d0%02d', (localtime)[2, 1, 0]; for my $mask (8, 4, 2, 1) { print " "; for my $d (split //, $time) { print $d & $mask ? '## ' : ' '; } print "\n $mask "; for my $d (split //, $time) { print $d & $mask ? '## ' : ' '; } print "\n\n"; } print " HH HH MM MM SS SS\n";
As you appear to want to run this in a loop, and display the result in a terminal window, you'll likely will have to dig into ANSI codes. You can change foreground and background colors, which may allow you to just print colored spaces. There are also control codes to move the cursor to any place on the screen.
A quick Goolge search brought me to this page, which might just contain enough info to make it do what you want: VT-100 Escape Codes
OK, let's test it.
Blimey, it works.#!/usr/local/bin/perl -w my $old = ''; print "\e[2J"; while(1){ print "\e[1;1H"; my $time = sprintf '%02d0%02d0%02d', (localtime)[2, 1, 0]; if($time eq $old) { sleep 1; redo; } $old = $time; for my $mask (8, 4, 2, 1) { print " "; for my $d (split //, $time) { print $d & $mask ? "\e[7m \e[m " : ' '; } print "\n $mask "; for my $d (split //, $time) { print $d & $mask ? "\e[7m \e[m " : ' '; } print "\n\n"; } print " HH HH MM MM SS SS\n"; sleep 1; }
Update: Fixed bug in fetching time always with 2 digits.
In reply to Re: Binary Clock
by bart
in thread Binary Clock
by Legg83
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |