RosettaCodeData/Task/Draw-a-clock/Perl/draw-a-clock-2.pl
2026-04-30 12:34:36 -04:00

22 lines
493 B
Perl

#!/usr/bin/perl
use strict; # https://rosettacode.org/wiki/Draw_a_clock
use warnings;
use Tk;
my $halfsize = 200;
my $twopi = 2 * atan2 0, -1;
my $mw = MainWindow->new;
my $c = $mw->Canvas( -width => 2 * $halfsize, -height => 2 * $halfsize)->pack;
$mw->repeat(1000 => \&draw);
MainLoop;
sub draw
{
$c->delete('all');
my $angle = time % 60 / 60 * $twopi;
$c->createLine( $halfsize, $halfsize,
$halfsize * (1 + sin $angle),
$halfsize * (1 - cos $angle),
-width => 5);
}