#!/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; } }