in reply to Shrinking Pie Analog Countdown Timer

If you get Tk to work, this is one way to do it. It draws 360 tagged segements in the background color (so they are invisible, and when the spacebar is pressed, changes their color to black making them visible. It then sets up a repeating, timed callback that makes the segments invisible again one at a time.

#! 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( '<space>', 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 t +o red if( $tag == 90 ) { printf "\a"; $canvas->itemconfigure( "t$_", -fill => 'red' ) for 0 .. 9 +0; } ## make the next segment invisible. $canvas->itemconfigure( "t$tag", -fill => 'white' ); --$tag; ## Next segment to remove. }); }); $mw->MainLoop;

There is a fudge factor in the timer calculation (using 850 instead of 1000 milliseconds), to account for processing time. 850 workd fairly well for short countdowns (5 to 30 seconds) on my machine, but it will need adjusting to accomodate your processor and graphics card performance.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Shrinking Pie Analog Countdown Timer
by eric256 (Parson) on May 24, 2006 at 19:38 UTC

    Stealing liberaly and recoding a little. This does the same thing (mostly) but without all the different slices. This lets you set the angle that you could like to be removed every frame and the timer length. Moved configuration data to the top and thats about it. Mine is probably worse in some ways or better in others, but in reality i was just playing and thought i would share.

    #! perl -slw use strict; use warnings; use Time::HiRes qw[ time ]; use Tk::Canvas; my $inc = 1; #degrees to move each frame my $length = 10; #seconds to take my ($width, $height) = (480,480); my $trip_point = 90; my $code = 'A123BC'; my $repeatTime = ($length * 1000) / (360 / $inc); my $mw = MainWindow->new; my $canvas = $mw->Canvas( -width => $width, -height => $height, -bg => 'black', )->pack; my $start = 359; my $arc = $canvas->createArc( 0, 0, $width, $height, -fill => 'white', -outline => undef, -extent => $start, -start => 90, -tag => 'arc', ); ## Bind action to space bar $mw->bind( '<space>', sub { my $rep; my $tripped = 0; ## Set up the repeating callback with the delay calculated earlier $rep = $mw->repeat( $repeatTime, sub { $start -= $inc; $canvas->itemconfigure('arc', -extent => $start ); if ($start < 0) { $canvas->itemconfigure('arc', -extent => 0); $rep->cancel; printf "\a"; $canvas->createText($width / 2, $height /2, -text => $code, -tag => 'code', -fill => 'red', ); } elsif ($start < $trip_point and !$tripped) { printf "\a"; $tripped = 1; $canvas->itemconfigure('arc', -fill => 'red'); } }); }); $mw->MainLoop;

    Update: .... errr cut and pasted the wrong file, sorry bout that.


    ___________
    Eric Hodges

      Um. Exactly what did you change? :)


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Thats what i get for cut and pasting without having my morning soda!;) all fixed now


        ___________
        Eric Hodges