Result of a few hours hacking and requesting for hints and mathematics to some people.
#!/usr/bin/perl
$d=`date +%l:%M`;chomp($d);($h,$m)=
split(/:/,$d); $h=0 if $h==12;$h=($h*30)+180; $h-=
360 if $h>360;$m = ($m*6)+180;$m-=360 if $m>360;@o
=([' ', ' ',' ',
' ',' ' ,' ',' '
, ' ' , ' ',' ',
' ',' ' ,' ' ,' ','|'
],[' ', ' ', ' ',' ',
' ',' ' ,' ' ,' ',' '
, ' ' , ' ', ' ',' ',
' ','|' ], [ ' ',' ',
' ',' ' ,' ' ,' ',' '
, ' ' , ' ', ' ',' ',
' ',' ' ,' ' ,'|'] ,[
' ',' ' ,' ', ' ',' ',
' ',' ' ,' ' ,' ',' '
, ' ' , ' ', ' ',' ',
'|'] ,[ ' ', ' ',' ',
' ',' ' ,' ' ,' ',' '
, ' ' , ' ', ' ',' ',
' ',' ' ,'|' ], [' ',
' ',' ' ,' ' ,' ',' '
, ' ' , ' ', ' ',' ',
' ',' ' ,' ',' '
,'|'],[ ' ',' ',
' ',' ' ,' ',' '
,' ',' ' ,' ',' '
,' ',' ',' ',' ','|'],[' ',' ',' ',' ',' ',' ',' '
,' ',' ',' ',' ',' ',' ',' ','|'],[' ',' ',' ',' '
,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'],[' '
,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' ,
' ','|'],[' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ','|'],[' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ','|'],[' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'],[' ',
' ',' ',' ',' ',' ',' ',' ',' ', ' ', ' ',' ',' ',
' ','|'],[' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ','|'],[' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ','|'],[' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|']); sub
dl {$l=$_[2]; while($l-- > 1){$o[int($_[0]+($l*cos
($_[3])))][int($_[1]+($l*sin($_[3])))]=$_[4];}}sub
cc {@c=('|','/','-','\\','|','/','-','\\'); return
$c[int((abs($_[0])+22.5)/45)];}dl(7,7,5,-(($h/180)
*3.1415),&cc(-$h));dl(7,7,7,-(($m/180)*3.1415),&cc
(-$m));sub pm {print "-"x29,"\n"; for($z=0;$z<$#o;
$z++){print "@{$o[$z]}\n";}print "="x29,"\n";}±
print " ---> $d <--- \n";
# Analog Obfuscated Clock
# by Gilberto "Velenux" Ficara, March 2004
#
# Thanks to Cyberbrown, Javanx, lu_zero, gmax
# and noteof for useful hints, algorithms and
# supplying to me the mathematics I lack
Re: What time is it? by muba (Chaplain) on Mar 22, 2004 at 21:38 UTC |
Unfortunately, it doesn't work on W32, because of the `date ...` part. | [reply] [d/l] |
|
Sorry, but I was not thinking about making it portable ;)
| [reply] |
|
Velenux,
I hope you don't mind - this should make it portable:
#!/usr/bin/perl
use POSIX 'strftime';
$d=strftime("%l:%M", localtime);chomp($d);($h,$m)=
split(/:/,$d); $h=0 if $h==12;$h=($h*30)+180; $h-=
360 if $h>360;$m = ($m*6)+180;$m-=360 if $m>360;@o
=([' ', ' ',' ',
' ',' ' ,' ',' '
, ' ' , ' ',' ',
' ',' ' ,' ' ,' ','|'
],[' ', ' ', ' ',' ',
' ',' ' ,' ' ,' ',' '
, ' ' , ' ', ' ',' ',
' ','|' ], [ ' ',' ',
' ',' ' ,' ' ,' ',' '
, ' ' , ' ', ' ',' ',
' ',' ' ,' ' ,'|'] ,[
' ',' ' ,' ', ' ',' ',
' ',' ' ,' ' ,' ',' '
, ' ' , ' ', ' ',' ',
'|'] ,[ ' ', ' ',' ',
' ',' ' ,' ' ,' ',' '
, ' ' , ' ', ' ',' ',
' ',' ' ,'|' ], [' ',
' ',' ' ,' ' ,' ',' '
, ' ' , ' ', ' ',' ',
' ',' ' ,' ',' '
,'|'],[ ' ',' ',
' ',' ' ,' ',' '
,' ',' ' ,' ',' '
,' ',' ',' ',' ','|'],[' ',' ',' ',' ',' ',' ',' '
,' ',' ',' ',' ',' ',' ',' ','|'],[' ',' ',' ',' '
,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'],[' '
,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' ,
' ','|'],[' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ','|'],[' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ','|'],[' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'],[' ',
' ',' ',' ',' ',' ',' ',' ',' ', ' ', ' ',' ',' ',
' ','|'],[' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ','|'],[' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ','|'],[' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|']); sub
dl {$l=$_[2]; while($l-- > 1){$o[int($_[0]+($l*cos
($_[3])))][int($_[1]+($l*sin($_[3])))]=$_[4];}}sub
cc {@c=('|','/','-','\\','|','/','-','\\'); return
$c[int((abs($_[0])+22.5)/45)];}dl(7,7,5,-(($h/180)
*3.1415),&cc(-$h));dl(7,7,7,-(($m/180)*3.1415),&cc
(-$m));sub pm {print "-"x29,"\n"; for($z=0;$z<$#o;
$z++){print "@{$o[$z]}\n";}print "="x29,"\n";}±
print " ---> $d <--- \n";
# Analog Obfuscated Clock
# by Gilberto "Velenux" Ficara, March 2004
#
# Thanks to Cyberbrown, Javanx, lu_zero, gmax
# and noteof for useful hints, algorithms and
# supplying to me the mathematics I lack
Cheers - L~R
| [reply] [d/l] |
|
Re: What time is it? by teamster_jr (Curate) on Mar 23, 2004 at 11:50 UTC |
very nice.
you could also wrap the whole thing in this:
{
# clear the screen
print "\ec";
# draw your clock
<your code>
# wait and redo
sleep 1; redo
}
also see these for my obfu'd timepieces - yours looks nicer!
Alex
Update: Actually i realised you only draw minutes, so you could sleep 60 - slightly less redrawing
Also I'm not sure print "\ec" works on everything - so perhaps a nicer way would be to use <check os here>?`clear`:`cls`;
| [reply] [d/l] [select] |
|
<check os here>?`clear`:`cls`;
You need a print for that one, as `clear` actually prints
escape sequence, so <check os here>?print`clear`:`cls`.
Also, I think that just print`cls;clear`
should work too, as on windows this gives cls a command-line
argument which it probably ignores (or it obeys it and
makes the console real shiny clear); on linux the clear
should hide whatever error cls prints.
| [reply] [d/l] [select] |
|
|