Just to give you some tips ( we all needed them). If you change your increment 0.05 to a variable, you can make a widget to set it in realtime as a textvariable, and you can have adjustable speed control.
You can't change the delay of the repeater dynamically, but you can fudge around it by adjusting how far something moves during that period.
#!/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;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.