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) :-)
Now you can also do it to bind each outerring ball to a separate callback.# 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);
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 %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, $_ ] ) ; }
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.
In reply to Re: for loops
by zentara
in thread for loops
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |