update: Just in case you get the wrong impression, I am not "Walter C. Mankowski".
A time display's nice, but an analog clock is nicer(screenshot).
#!/usr/bin/perl # $Log: tk_internet_time,v $ # Revision 1.2 1999/06/27 03:46:49 waltman # Added copyright notice # Added some comments # Removed fonts (just use whatever the default is) # Improved visual appearance of clock # Cleaned out some test code # Removed "@" from the sprintf in itime() # # Revision 1.1 1999/06/27 03:34:19 waltman # Initial revision # # Copyright 1999 Walter C. Mankowski # You may copy and distribute this program under the # same terms as Perl iteself. use Tk; my $mw = MainWindow->new; $mw->title("Internet Time"); # $canvas is where the analog clock goes my $canvas = $mw->Canvas(-height => 210, -width => 210)->pack(-side => 'top', -expand => 1); # $label is where the digital clock goes my $label = $mw->Label(-text => '@' . substr(&itime,0,3), )->pack(-side => 'top', -expand => 1); # periodically update the digital clock $label->repeat( 1000, sub{$label->configure(-text => '@' . substr(&itime,0,3))} ); # Draw the analog clock $canvas->createOval(5, 5, 205, 205, -width => 5); # the outer + circle $canvas->createOval(100,100, 110, 110, -fill => "black"); # where the + hands # meet &DrawTicks; # ticks aro +und the # outside &DrawHands ($canvas, &itime,1); # hands # periodically move the hands $canvas->repeat( 500, \&RedrawHands, $canvas); &MainLoop; sub itime { my $s = sprintf "%07.3f", ((time+3600) % 86400)/86.4; return $s; } sub DrawHands { my ($canvas, $t) = @_; $hand1 = &DrawHand ($canvas, $t / 1000, 50, 10); $hand2 = &DrawHand ($canvas, substr($t,1) / 100, 75, 8); $hand3 = &DrawHand ($canvas, substr($t,2) / 10, 100, 6); $hand4 = &DrawHand ($canvas, substr($t,4) / 1000, 100, 2); } sub DrawHand { my ($canvas, $frac, $length, $line_width) = @_; my $pi = 3.14159; my $height; my $width; my $theta; my $hand; $theta = ($frac * 2 * $pi) - ($pi / 2); $height = $length * sin($theta); $width = $length * cos($theta); $hand = $canvas->createLine(105, 105, 105+$width, 105+$height, -arrow => "last", -width => $line_width); } sub RedrawHands { my $canvas = shift; $canvas->delete ($hand1, $hand2, $hand3, $hand4); &DrawHands ($canvas, &itime,1); } sub DrawTicks { my $pi = 3.14159; my $i; my ($h1, $w1, $h2, $w2); my $theta; my ($l1, $l2) = (85, 100); foreach $i (1..100) { if ($i % 10 == 0) { $l1 = 80; } elsif ($i % 5 == 0) { $l1 = 90; } else { $l1 = 95; } $theta = ($i/100 * 2 * $pi) - ($pi / 2); $h1 = $l1 * sin($theta) + 105; $w1 = $l1 * cos($theta) + 105; $h2 = $l2 * sin($theta) + 105; $w2 = $l2 * cos($theta) + 105; $canvas->createLine($w1, $h1, $w2, $h2); } }

 
___crazyinsomniac_______________________________________
Disclaimer: Don't blame. It came from inside the void

perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"


In reply to (crazyinsomniac) Re: PerlTK, Time Display, and You. by crazyinsomniac
in thread PerlTK, Time Display, and You. by dneedles

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.