#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Zinc; my $motion_flag = 0; my $count = 0; my $delay = 100; #adjust for speed of your computer 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', -priority => 2 ); #examine the curves_bezier demo script to play with bezier points ############################################################################## #make a group for the flower petals my $flower = $zinc->add('group',1,-visible => 1); print "flowergroup-> $flower\n"; #make a flower my $petal = $zinc->add('curve',$flower,[[350, 281], [200,100, 'c'], [500,100, 'c'], [350,281]], -tags => ['bezier1'], -filled => 1, -fillcolor => 'pink', -closed => 1, -linecolor => "white", -linewidth => 5); print "$petal\n"; #prints $zinc's widget identifier my $petalcount=1; for my $color (qw(magenta blue cyan green yellow red)) { my $colortemp = $color; my $color = $zinc->clone($petal); print "$color\n"; #prints $zinc's widget identifier $zinc->itemconfigure($color,-fillcolor => $colortemp); $zinc->rotate($color,.9*$petalcount,350,281); $petalcount++; } ############################################################################## # Display comment &comment("Hit Enter to begin."); #set key binding $mw->Tk::bind('', \&start); my $closebutton = $mw->Button(-text => 'Exit', -command => sub{Tk::exit(0)}) ->pack; MainLoop; sub start { &comment("Hit Esc to stop, 'r' to reset. Up arrow inreases speed Down arrow decreases speed Left arrow moves left 1 pixel Right Arrow moves right 1 pixel 'z' zoom out, 'a' zoom in"); $count =0; $motion_flag = 1; $mw->Tk::bind('', sub{}); $mw->Tk::bind('', \&resetpos); &startaction; } sub stopaction{ # &comment("Hit Enter to begin"); $motion_flag = 0; $mw->Tk::bind('', \&start); } sub startaction { $mw->Tk::bind('', \&stopaction); $mw->Tk::bind('', sub{$delay = ($delay -1) unless $delay <= 1 }); $mw->Tk::bind('', sub{$delay = ($delay + 1)unless $delay >= 1000} ); $mw->Tk::bind('', sub{$zinc->translate($flower,1,0)}); $mw->Tk::bind('', sub{$zinc->translate($flower,-1,0)}); $mw->Tk::bind('', sub{$zinc->scale($flower,1.1,1.1)}); $mw->Tk::bind('', sub{$zinc->scale($flower,.9,.9)}); $mw->Tk::bind('', \&resetpos); $zinc->rotate($flower,.5,350,281); if($motion_flag == 1){ $zinc->after($delay, sub {startaction()})} else {return} } sub resetpos{ $zinc->treset($flower); } # Just display comment sub comment { my $string = shift; $zinc->itemconfigure($text, -text => $string); }