#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Zinc; 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')->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], #corners (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 #maintain an array of positions my ($x1,$y1,$x2,$y2,$x3,$y3) = my @initcoords = (0,0,20,0,10,40); my @pos1 = (130,20); #initial positions to translate to my $tr1 = $zinc->add('triangles', 1, [@initcoords], #(x1,y1,x2,y2,x3,y3) -fan => 1, -colors => 'Orange', -visible => 1, ); $zinc->translate($tr1,@pos1); # Display comment &comment("Hit Tab to begin, and then a few more times."); &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); &comment("Hit Escape to stop."); &startaction(); } sub stopaction{ &comment("Hit Tab to begin, then hit again a few times."); &wincomment("READY"); # Callback bound to '' event when pressed $mw->Tk::bind('', \&start); #thrown in to demonstrate shape-shifting $zinc->coords($tr1,[100,100,100,60,60,60]); #changes shape of triangle #not position } sub startaction { # move triangles $zinc->translate($tr1,0,10); #moves down 10 pixels } # 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); }