#! /usr/bin/perl use strict; use warnings; use Time::HiRes qw{ usleep }; use Tk; my $mw = 'MainWindow'->new(-title => 'Event demo'); $mw->bind('<>' => \&next_row); my $drawarea = $mw->Frame->pack(-side => 'top', -fill => 'both'); my $p = $mw->Photo(-width => 500, -height => 500); my $canvas = $drawarea->Canvas( -relief => 'ridge', -width => 500, -height => 500, -borderwidth => 4 )->pack; $canvas->createImage(0, 0, -anchor => 'nw', image => $p); $mw->Button(-text => 'Plot', -command => \&init) ->pack(-side => 'left'); $mw->Button(-text => 'Stop', -command => \&stop) ->pack(-side => 'left'); $mw->Button(-text => 'Quit', -command => sub { Tk::exit() }) ->pack(-side => 'left'); MainLoop(); { my ($y, $done); sub init { undef $done; $y = 0 if ! defined $y || $y == 500; $mw->eventGenerate('<>'); } sub next_row { return if $done; for my $x ( 0..499 ) { my $quality = long_computation($x, $y); $p->put(color($quality), '-to', $x, $y); } $canvas->update; if (++$y < 500) { $mw->eventGenerate('<>', -when => 'tail' ); } } sub stop { $done = 1 } } sub color { qw( red blue )[ rand 2 ] } sub long_computation { usleep(100) } #### ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,