Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Tk ASCII Draw on Canvas

by tybalt89 (Parson)
on Jun 25, 2019 at 06:14 UTC ( #11101849=note: print w/replies, xml ) Need Help??


in reply to Re: Tk ASCII Draw on Canvas
in thread Tk ASCII Draw on Canvas

Here's a little proof-of-concept of one way to implement a "pen" in Canvas.

#!/usr/bin/perl use strict; use warnings; use Tk; my @lines; my $mw = MainWindow->new; my $c = $mw->Canvas(-width => 900, -height => 900,)->pack(-side => 'bo +ttom'); $mw->Button(-text => $_->[0], -command => $_->[1])->pack(-side => 'rig +ht') for [ Exit => sub { $mw->destroy } ], [ 'Clear Last' => sub { pop @lines; redraw() } ], [ 'Clear All' => sub { @lines = (); redraw() } ]; $c->Tk::bind('<1>' => sub { push @lines, [ &xy ]; redraw(); $c->Tk::bind('<Motion>' => sub { push @{ $lines[-1] }, &xy; redraw() + } ); } ); $c->Tk::bind('<ButtonRelease-1>' => sub { $c->Tk::bind('<Motion>' => ' +') } ); MainLoop; sub xy { $_[0]->XEvent->x, $_[0]->XEvent->y } sub redraw { $c->delete('pen'); @$_ >= 4 and $c->createLine(@$_, -smooth => 1, -width => 5, -tag => +'pen') for @lines; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2019-10-16 06:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?