Thread Perl TK - Programm
(34 answers)
Opened by betterworld at 2003-10-26 00:14
[quote=BrownWolf,26.10.2003, 05:39]Und Uhren kann man damit auch basteln *G*[/quote]
Digitaluhr, wie langweilig. ;) Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 #!/usr/bin/perl use strict; use warnings; use Tk; use constant PI => 3.1415927; my $Size = 100; my @Weekdays = qw/Son Mon Die Mit Don Fre Sam/; my ($HSec, $HMin, $HHour, $Date); my $Mw = MainWindow->new; my $HFace = $Mw->Canvas (-width => 2*$Size, -height => 2*$Size)->pack; my $DText = $Mw->Label (-textvariable => \$Date)->pack; $HFace->createLine (tc(0.9, $_), tc(1, $_)) for (0..11); drawtime(); $Mw->repeat (1000, \&drawtime); $Mw->MainLoop(); sub drawtime { my ($s, $m, $h, $dy, $mn, $yr, $wd) = (localtime())[0..6]; $Date = sprintf("%s, %02d.%02d.%04d", $Weekdays[$wd], $dy, $mn+1, $yr+1900); $h+=$m/60; for ($HSec, $HMin, $HHour) { $HFace->delete($_) if $_; } $HSec = $HFace->createLine ($Size, $Size, tc(0.88, $s/5)); $HMin = $HFace->createPolygon (tc(0.85, $m/5), tc(0.05, ($m/5+4)), tc(0.05, ($m/5-4))); $HHour = $HFace->createPolygon (tc(0.5, $h), tc(0.05, $h+4), tc(0.05, $h-4)); $Mw->update; } sub tc { my ($scale, $time) = @_; return ($Size*$scale*sin($time*PI/6)+$Size, -$Size*$scale*cos($time*PI/6)+$Size); } Edit: Monat+1 gefixt.\n\n <!--EDIT|Dubu|1067423409--> |