in reply to Stone Jam -- 21 challenging puzzles with perl Tk
I wI was for some method to produce some brick-like piece unable to collide themselves.as for some method to produce some brick-like piece unable to collide themselves.
Try this tag method.
#!/usr/bin/perl use warnings; use strict; use Tk; my $dx; my $dy; my $mw = MainWindow->new; $mw->geometry("700x600"); my $canvas = $mw->Canvas(-width => 700, -height => 565, -bg => 'black', -borderwidth => 3, -relief => 'sunken', )->pack; my $closebutton = $mw->Button(-text => 'Exit', -command => sub{Tk::exi +t(0)}) ->pack; my $dr = $canvas->createPolygon(0, 20, 50, 20, 50, 75, 0,75, -fill => 'red', -tags => ['move','red','paver'], ); my $db = $canvas->createPolygon(70, 20, 150,20, 150, 75, 70 , 75, -fill => 'blue', -tags => ['move','blue','paver'], ); my $dg = $canvas->createPolygon(200, 20, 250,20, 250, 75, -fill => 'green', -tags => ['move','green','paver'], ); my $dp = $canvas->createPolygon(300, 20, 350,20, 350, 75, -fill => 'purple', -tags => ['move','purple','paver'], ); $canvas->bind('move', '<1>', sub {&mobileStart();}); $canvas->bind('move', '<B1-Motion>', sub {&mobileMove();}); $canvas->bind('move', '<ButtonRelease-1>', sub {&mobileStop();}); MainLoop; sub mobileStart { my $ev = $canvas->XEvent; ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); $canvas->raise('current'); # print "START MOVE-> $dx $dy\n"; } sub mobileMove { my $ev = $canvas->XEvent; # $canvas->bind('current', '<Leave>', sub {&mobileStop();}); + my @coords_in = $canvas->coords('current'); # print "@coords_in\n"; $canvas->move('current', $ev->x + $dx, $ev->y +$dy); ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); # print "MOVING-> $dx $dy\n"; my @coords = $canvas->coords('current'); #print "@coords\n"; my (@olaps) = $canvas->find('overlapping', $coords[0],$coords[1] +,$coords[4],$coords[5], ); foreach my $id(@olaps){ print $canvas->gettags($id),"\t"; } print "@olaps\n"; print "\n"; if(scalar @olaps > 1){ # Redraw the rect $canvas->coords('current', @coords_in); } } sub mobileStop{ &mobileMove; }
what happened to the -tile option for canvas? How can I fill canvas objects (rectangles, ovals..) with Photos or advanced grafic?
I don't think there is a canvas -tile option for it's objects. What you would need to do is create canvas image objects of the appropriate size and manipulate them. See Tk ImageMap-color-zones for an example.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Stone Jam -- 21 challenging puzzles with perl Tk
by choroba (Cardinal) on May 03, 2018 at 13:26 UTC | |
by zentara (Cardinal) on May 03, 2018 at 18:02 UTC |