#!/usr/bin/perl --
use strict;
use warnings;
use Tk 8;
my $mw = tkinit( -width => 500, -height => 500 );
my $canvas = $mw->Canvas()->pack( -expand => 'yes', );
$canvas->createOval( 50, 50, 100, 100, -fill => 'white', -tags => ['le
+ft'] );
$canvas->createOval( 60, 50, 70, 60, -fill => 'red', -tags => ['left i
+ris'] );
$canvas->createOval(
100 + 50, 50, 100 + 100, 100,
-fill => 'white',
-tags => ['right']
);
$canvas->createOval(
100 + 80, 80, 100 + 90, 90,
-fill => 'red',
-tags => ['right iris']
);
$mw->bind( 'Tk::Canvas', '<Motion>' => [ \&marine, Ev('x'), Ev('y') ]
+);
use Math::Trig qw' atan pi ';
sub marine {
my ( $w, $x, $y ) = @_;
my $iris = 'left iris';
my $r = 25;
my $cx = 75;
my $cy = 75;
my $angle = eval { atan( ( $cy - $y ) / ( $cx - $x ) ) };
$angle += pi if ( $cx - $x ) >= 0;
my ( $x1, $y1, $x2, $y2 ) = $w->coords($iris);
$x1 = ( ( $r * cos($angle) + $cx ) );
$y1 = ( ( $r * sin($angle) + $cy ) );
$x2 = $x1 + 10;
$y2 = $y1 + 10;
$w->coords( $iris, $x1, $y1, $x2, $y2 );
}
MainLoop;
|