I'm not sure what types of binding you want to make, do you want to bind all of them to <1>?

I think you are overlooking "tags", but there are a few ways to do it. The array method is ok, but you would be better off using a hash. There are many different ways to do it, depending on whether you need separate callbacks for each ball or not.

untested( but close to correct) :-)

# first way with tags, all outer balls will be bound # to same callback my $refitem = $zinc->add('arc',$centergroup2, [ [10,20], [20,30] ], -filled => 1, -fillcolor => $refgrad, ## $refgrad -linewidth => 0, -priority => 100 -tags => ['outerring'], ); # make/clone 11/12 more of the above for (1..11){ my $relement = $zinc->clone($refitem); $zinc->rotate($relement,.53*$_); } $zinc->bind( 'outerring', '<1>', \&ro6);
Now you can also do it to bind each outerring ball to a separate callback.
my %refitems; my $refitem = $zinc->add('arc',$centergroup2, [ [10,20], [20,30] ], -filled => 1, -fillcolor => $refgrad, ## $refgrad -linewidth => 0, -priority => 100 ); # make/clone 11/12 more of the above for (1..11){ $refitem{$_} = $zinc->clone($refitem); $zinc->rotate($refitem{$_},.53*$_); #here you bind each one separately, and/or #pass extra info to the callback $zinc->bind( $refitem{$_}, '<1>', [ \&ro6, $_ ] ) ; }
As you can see, there are more than one way to do it. You can even assign the hash element as a tag, although it is a bit redundant; however it allows you to search for items thru the tag mechanism. I include it just to reinforce the idea that you can throw anything into the item's tags.
my $refitem = $zinc->add('arc',$centergroup2, [ [10,20], [20,30] ], -filled => 1, -fillcolor => $refgrad, ## $refgrad -linewidth => 0, -priority => 100 -tags => ['outerring'], ); my %refitems; # make/clone 11/12 more of the above for (1..11){ $refitem{$_} = $zinc->clone($refitem); $zinc->addtag($refitem{$_}, $refitem{$_}); $zinc->rotate($refitem{$_},.53*$_); #here you bind each one separately, and/or #pass extra info to the callback $zinc->bind( $refitem{$_}, '<1>', [ \&ro6, $_ ] ) ; }

Anyways, those are some ideas to explore. When you have more than 1 item, that you want to bind to the same callback, you can use tags, or pass an extra arg to the bind callback, to identify which ball called it.


I'm not really a human, but I play one on earth. flash japh

In reply to Re: for loops by zentara
in thread for loops by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.