in reply to plotting slowly
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new; my $x = 0; my $y = 0; my $pi = 3.1415926; my $counter=0; my $c = $mw->Canvas(-width => 500, -height => 500); $c ->pack; # draw axis $c -> createLine(50, 250, 450, 250); $c -> createText(10, 250, -fill => 'blue', -text => 'X'); $c -> createLine(250, 50, 250, 450); $c -> createText(250, 10, -fill => 'blue', -text => 'Y'); $x = -(3*$pi); my $repeater; # declare separately so you can # stop it in it's own callback $repeater = $mw->repeat(50,sub{ # 50 millisecond delay $x += 0.05; if( $x >= +(3*$pi) ){ $repeater->cancel } $y = sin($x); $c -> createText( $x*30+250, $y*30+250, -fill => 'red', -text => '.'); }); MainLoop;
|
|---|