#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Zinc; my $motion_flag = 0; my $mw = MainWindow->new; $mw->geometry("700x600"); $mw->resizable(0,0); my $zinc = $mw->Zinc(-width => 700, -height => 565, -backcolor => 'black', -borderwidth => 3, -relief => 'sunken'); $zinc->pack; # Then we create a gray filled rectangle, in which we will display explain text. $zinc->add('rectangle', 1 , [200, 400, 490, 490], -linewidth => 2, -filled => 1, -fillcolor => 'SkyBlue', ); my $text = $zinc->add('text', 1, -position => [350, 445], -anchor => 'center', ); $zinc->add('rectangle', 1 , [250,275,450,325], #(xpos1,ypos1,xpos2,ypos2) -linewidth => 2, -filled => 1, -fillcolor => 'Orange', ); my $wintext = $zinc->add('text', 1, -position => [350, 300], -anchor => 'center', ); #create triangles #create first triangle, then clone and translate my $tr1 = $zinc->add('triangles', 1, [0,20,20,20,10,50], -fan => 1, -colors => 'Orange', -visible => 1, ); my $tr2 = $zinc->clone($tr1); my $tr3 = $zinc->clone($tr1); $zinc->translate($tr1,130,0); $zinc->translate($tr2,340,0); $zinc->translate($tr3,550,0); # Display comment &comment("Strike any key to begin"); &wincomment("READY"); # Create Tk binding $mw->Tk::bind('', \&start); my $closebutton = $mw->Button(-text => 'Exit', -command => sub{Tk::exit(0)}) ->pack; MainLoop; sub start { # set binding to stop and exit $mw->Tk::bind('', \&stopaction); $motion_flag = 1; &comment("Strike any key to exit."); &startaction(); } sub stopaction{ $motion_flag = 0; &comment("Strike any key to begin"); &wincomment("READY"); $mw->Tk::bind('', \&start); $zinc->coords($tr1,[100,100,100,60,60,60]); #changes shape of triangle $zinc->coords($tr2,[100,100,100,60,60,60]); #not position $zinc->coords($tr3,[100,100,100,60,60,60]); $zinc->translate($tr1,0,-150); #changes position $zinc->translate($tr2,0,-150); $zinc->translate($tr3,0,-150); } # Callback bound to '' event when pressed sub startaction { # move triangles $zinc->translate($tr1,0,1); $zinc->translate($tr2,0,1); $zinc->translate($tr3,0,1); if($motion_flag == 1){ $zinc->after(1, sub {startaction()})} else {return} } # Just display comment sub comment { my $string = shift; $zinc->itemconfigure($text, -text => $string); } # display winning comment sub wincomment { my $string = shift; $zinc->itemconfigure($wintext, -text => $string); }