http://www.perlmonks.org?node_id=800025

cmv has asked for the wisdom of the Perl Monks concerning the following question:

Monks-

How can I create an arc (-style=>'chord') with an arrow on the end, in a Perl-Tk canvas?

This sounded like a simple thing for me to answer. It's turning into a quagmire. Here's where I've been so far:

  • Arrow option on $can->createArc()? Nope - arrow option on line items only.
  • Make an arc out of a bunch of lines (needed to ask in CB for math formula).
  • Duh, CB suggestion to put a small line on end of arc, with arrow! Good thinking..., but wait - I can't figure out how to do this, since there's no way I know of to get the coords of the end of the arc to attach a line to (you only get coords of a rectangle that encloses the arc). Back to bunch-o-lines strategy.
  • Built bunch-o-lines prototype (see attached), but arrowhead doesn't follow curve, and there's no way to rotate the arrowhead.
  • Thinking I could create a really short line right at the end, that orients the arrow in the correct direction. Started thinking there has to be a better way. Decided to ask for Monk's help.

    Any thoughts are much appreciated.

    Thanks

    -Craig

    use strict; use warnings; use Tk; my $top = MainWindow->new; my $can = $top->Canvas()->pack(); my @offset = (100, 100); my $PI = atan2(1,1) * 4; my $max = 100; my $radius = 20; my @coords; foreach my $i (1..$max-30) { push(@coords, _circleCoord($i*2*$PI/$max, $radius)); } $can->createLine(@coords, -arrow=>'last', #-arrowshape=>[10, 15, 9], # Goofy arrowhead - this helps tags=>['SELFARROW']); $can->move('SELFARROW', @offset); MainLoop; sub _circleCoord { my $radians = shift || die "Missing radians"; my $radius = shift || die "Missing radius"; my @coords; push(@coords, ($radius * sin($radians))); push(@coords, ($radius * cos($radians))); return(@coords); }