#! perl -slw use strict; use Time::HiRes qw[ time ]; use Tk::Canvas; our $TIME ||= 10; ## Fudge factor! using 850 instead of a 1000 works ## reasonably well for timeperiods of 5 to 30 seconds ## on my machine. Adjust to suit processor speed. my $repeatTime = int( 850 * $TIME / 360 ); print $repeatTime; my $mw = MainWindow->new; my $canvas = $mw->Canvas( -width => 640, -height => 480, -bg => 'white', )->pack; ## Create 360 tagged segments white (invisible). for my $tag ( 0 .. 359 ) { $canvas->createArc( 80, 0, 560, 480, -fill => 'white', -outline => undef, -start => $tag + 90, -extent => 1, -tag => "t$tag", ); } ## Bind action to space bar $mw->bind( '', sub { ## remove previous alphanumeric code $canvas->delete( 'code' ); print time(); ## make circle visible by setting the color of the segments $canvas->itemconfigure( "t$_", -fill => 'black' ) for 0 .. 359; my $tag = 359; ## Start with the first tag to 'remove'. my $rep; ## Set up the repeating callback with the delay calculated earlier $rep = $mw->repeat( $repeatTime, sub { ## if the last segment has been removed ## beep, display the code and cancel the timer. if( $tag < 0 ) { printf "\a"; $canvas->createText( 300, 240, -text => 'AN ALPHA-NUMERIC CODE', -tag => 'code' ); $rep->cancel; print time(); } ## If a quater of the circle left, beep and change the color to red if( $tag == 90 ) { printf "\a"; $canvas->itemconfigure( "t$_", -fill => 'red' ) for 0 .. 90; } ## make the next segment invisible. $canvas->itemconfigure( "t$tag", -fill => 'white' ); --$tag; ## Next segment to remove. }); }); $mw->MainLoop;