Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
29
Task/Draw-a-clock/Perl/draw-a-clock-1.pl
Normal file
29
Task/Draw-a-clock/Perl/draw-a-clock-1.pl
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use utf8; # interpret source code as UTF8
|
||||
binmode STDOUT, ':utf8'; # allow printing wide chars without warning
|
||||
$|++; # disable output buffering
|
||||
|
||||
my ($rows, $cols) = split /\s+/, `stty size`;
|
||||
my $x = int($rows / 2 - 1);
|
||||
my $y = int($cols / 2 - 16);
|
||||
|
||||
my @chars = map {[ /(...)/g ]}
|
||||
("┌─┐ ╷╶─┐╶─┐╷ ╷┌─╴┌─╴╶─┐┌─┐┌─┐ ",
|
||||
"│ │ │┌─┘╶─┤└─┤└─┐├─┐ │├─┤└─┤ : ",
|
||||
"└─┘ ╵└─╴╶─┘ ╵╶─┘└─┘ ╵└─┘╶─┘ ");
|
||||
|
||||
while (1) {
|
||||
my @indices = map { ord($_) - ord('0') } split //,
|
||||
sprintf("%02d:%02d:%02d", (localtime(time))[2,1,0]);
|
||||
|
||||
clear();
|
||||
for (0 .. $#chars) {
|
||||
position($x + $_, $y);
|
||||
print "@{$chars[$_]}[@indices]";
|
||||
}
|
||||
position(1, 1);
|
||||
|
||||
sleep 1;
|
||||
}
|
||||
|
||||
sub clear { print "\e[H\e[J" }
|
||||
sub position { printf "\e[%d;%dH", shift, shift }
|
||||
22
Task/Draw-a-clock/Perl/draw-a-clock-2.pl
Normal file
22
Task/Draw-a-clock/Perl/draw-a-clock-2.pl
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#!/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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue