Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Perl Tk canvases / abuse...

by choroba (Archbishop)
on May 11, 2021 at 23:02 UTC ( #11132440=note: print w/replies, xml ) Need Help??


in reply to Perl Tk canvases / abuse...

I wasn't able to reproduce the problem. Also, the script needed some changes to run under strict.

The word "tag" has a special meaning in the Tk domain. You aren't storing any tags in the @TAGS array, you're storing ids of the rectangles.

What about using a single tag for the background?

$canvas->createRectangle( $i * $ps, $j * $ps, $i * $ps + $ps, $j * $ps + $ps, -fill => $c, -outline => $c, -tags => ['bg']); }
The erase routine can be now simplified to
sub erase{ $canvas->delete('bg'); }
No need to store any tags/ids anywhere. That's usually the reason why to use the Canvas.

Update: I would also use tags for the lines, so you can easily raise them above the new background.

$canvas->createLine($start_x, $start_y, $x1, $y1, -width => 2, -fill => 'white', -tags => ['fg']); # ... # and after drawing the new background: $canvas->raise('fg', 'bg');

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Perl Tk canvases / abuse...
by Montain_Gman (Initiate) on May 12, 2021 at 12:05 UTC
    Thanks; I have longer response in second reply below. For the tags (ids); I know if i keep drawing stuff and don't delete; it will definitely bog down. I assume that's just because you are forcing the TK side to keep track of all that stuff, and it just has more and more work to do to figure out what is on top. Ok; I see what you did with the bg tag as well; that may help. When I saw that first thing this morning I thought you had stacked all the pixels into a single call; but now I see it's just more tieing them to a tag. Doing that, might make tk's job easier as well. Thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11132440]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2021-08-02 10:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (23 votes). Check out past polls.

    Notices?