If memory serves, once you pass control off to Tk's MainLoop() call, I don't think the sleep() call will make much difference. Instead, you may have to use the after() or repeat() methods documented in Tk::after. In such a case, I believe you would define a callback function that you would pass to the after() or repeat() calls, along the lines of:

#!/usr/bin/perl use strict; use Tk; my $top = MainWindow->new(); my $canvas = $top->Canvas( width => 300, height => 245 )->pack(); my $origin_x = 110; my $origin_y = 70; my $PI = 3.141592635; my $circle_radius = 5; my $path_radius = 0; my $angle = 0; $canvas->repeat( 1000, sub { &animate( $origin_x, $origin_y, $PI, \$canvas, \$circle_radius, \$path_radius, \$angle ); } ); # Could also be done as follows, although there are # differences in the two methods # $canvas->repeat( # 1000, # [ \&animate, $origin_x, $origin_y, # $PI, \$canvas, \$circle_radius, # \$path_radius, \$angle # ] # ); MainLoop(); sub animate { my ( $origin_x, $origin_y, $PI, $canvas, $circle_radius, $path_radius, $angle ) = @_; $$angle += 10; $$circle_radius += 3; $$path_radius += 7; my $path_x = $origin_x + $$path_radius * cos( $$angle * $PI / 90 ); my $path_y = $origin_y - $$path_radius * sin( $$angle * $PI / 90 ); $$canvas->create( 'oval', $path_x - $circle_radius, $path_y - $circle_radius, $path_x + $circle_radius, $path_y + $circle_radius, -fill => 'yellow' ); $$canvas->create( 'line', $origin_x, $origin_y, $path_x, $path_y, -fill => 'slategray' ); if ( $$angle > 180 ) { $angle = 0; $$circle_radius = 5; $$path_radius = 0; } }

This seems to do most of what you were planning (with the exception that it loops rather than continuing outward, although that can be changed by commenting out my resetting of the circle and path radii).

Hope that helps....

Update 18-May-2006: Changed call method to use anonymous subroutine rather than flat list, because there is the potiential for an apparent difference in the variables' contents between the two cases (in the case of the flat list, the variables have the values they contained at the time the constructor was called; in the case of the anonymous sub, the values they contained when the anonymous sub is actually invoked).

Update 18-May-2006: Added reference for reason for change in previous update.

Reference: Using advanced widgets in Perl/Tk by Philipp Janert, Ph.D.


In reply to Re: Animation Display appling Delay and Canvas Object by atcroft
in thread Animation Display appling Delay and Canvas Object by Alex Chew

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.