Perl 5 x 65 = 325 - 65(20%) = 260 chars!!
Clean, circular, with a second tick and updated every seconds.
perl -E '
$r=11;$p=atan2(1,1)/7.5;sub c{($A,$R,$C)=@_;$a[$r-$R*cos($A*$p)][
$r+$R*sin($A*$p)]=$C." "x($C!~/../)};while(::){@a=map{[map{" "}(
0..$r*2)]}(0..$r*2);map{c$_*5,$r,$_}(1..12);@t=localtime;for$i(qw
|H:6:5:2 M:8:1:1 s:9:1:0 |){($S,$P,$F,$T)=split":",$i;map{c$F*$t[
$T],$_,$S}(do{$T?1:$P}/10*$r..$P/10*$r)};map{say@{$_}}@a;sleep 1}
'
On a 24 lines console look good (It's 00:12:56):
12
11 1
s
10 H 2
H
H
H M M
H M M M
M M M
9 3
8 4
7 5
6
And there is a colored, nicer and smarter version:
#! /usr/bin/perl
use Time::HiRes qw|sleep time|
;$h=11;$h=$ARGV[0]if$ARGV[0];$P=atan2
(1,1)/7.5;$V =4*$h; $v= 2* $h+ 1;@r=(0..2*$v)
;sub p{printf @_ }sub b{ return"\e[1m"
.pop."\e[0m" };$ |=p"\e[?25".
"l\e[H\e[" ."J" ;$ SIG{ 'INT'}=sub
{p"\e[?1" ."2l" ."\e" ."[?25h".
"\e[%dH" ."\e" ."[J" ,$v+2;exit;
};@z=map {[map{" "
}@r] }(0 ..2*$v);
@Z=map{[@ {$z[$_]}]}@r
;sub c{($A,$r ,$s )=@_;$z[$h-$r*cos
($A*$P) +.5 ][$h+$ r*sin($A*$P)+.5]=$s;}
for$x( 0..$h) {$y= int(sqrt($h**2 -$x**2
)+.5);$ z[$h-$x][$h-$ y]=".";$z[$h+$x ][$h-$y
]="."; $z[$h-$x][$h+$ y]=".";$z[$h+$x ][$h+$
y]="."; $z[$h-$y][$h-$ x]=".";$z[$h+$y ][$h-$x
]="."; $z[$h-$y][$h+$x]=".";$z[$h+ $y][$h
+$x]="."};map{ c$_*5,$h,b$_}(1..12); @R=map{[@{$z[
$_]}]}@r;while (::){@t=localtime; p"\e[H\e[1;$
{V}H%0" ."2d\e[${v}H%02d\e" ."[${v
};${ V }H%02d",$t[2],$t[ 1],$t[
0];@z= map{[ @{$R[ $_]}]}(
0..2*$ v);for
$i('H:' .'65:5:'
.'2:4', "" x1 .'M:78:'
."1:1" .":2", "s:8". "7:1:"
.'0:6'){($ l,$p,$F,$u,$
c)=split ":",$i;map
{c$F*$t [$u],$_
,b("\e[" ."3${c}m$
l")}(do{$u ?1:$ p} / 100*$h..$p
/100*$h);} $z[$ h][ $h]= b((".","+"
,"*","o","O") [$t [0]%5]);for$x
(@r){for$y(@r ){$ Z[$x][$y]ne$z
[$x][$y]?p"\e[%d;%dH".$z [ $x] [$y],$x+1,2*$
y+1:''};};@Z=map{[@{$z[$_]}]}@r;$n=1-$1
if time=~/(\..*)$/;p"\e[H\e[7m"
."S\e[0m";sleep$n}
This version is strongly linked to this other answer, with the main advantage: You could run this quietly, for a while! So you could find an upgraded version there or on this ascii-clock for geeks web page.
As a demonstration that doing approx same in perl require less resources:
$ ascii-clock.pl 7
After PMem PCpu Mem
0' 0" 0.0% 0.0% 23.5M
10'30" 0.0% 0.0% 23.5M
1h 0' 0" 0.0% 0.0% 23.5M
2h 0' 0" 0.0% 0.0% 23.5M
for approx same features:
- wait for begin of each seconds for doing a refresh
- draw with color and bold attributes
- draw full circle with dots, hour tick, hour and minutes full path and a
s
dot for second handler. - draw digital clock prompting hour at top right, minutes at bottom left and seconds at bottom right.
- prompt a
S
at top left, when sleeping (look for difference with bash version)
Plus
- The upgraded version authorize
-a
argument for drawing hour and minute path in fraction (11h59 place hour path approx at 12h).
Let another perl version!!!
Using the following (beautiful) picture:
Than you could simply:
curl https://i.sstatic.net/xvbHP.png |
perl -e 'use GD;GD::Image->trueColor(1);$i=GD::Image->newFromPng(
STDIN);my($x,$y)=$i->getBounds();for my$k(0..$x-1){for my$l(0
..$y-1){$_.=pack"UUU",$i->rgb($i->getPixel($k,$l))};};eval'
Ok, this require having gd2-perl installed. But you could replace curl
by wget -O -
;-)
( Note: This picture is near 1.5Kb. I've built another same picture, but 900 bytes length. You may find this picture, well as a javascript version of same at ascii-clock for geeks :-)