Re: Event when clicking one of many Disks in a Pane
- To: mathgroup at smc.vnet.net
- Subject: [mg87448] Re: Event when clicking one of many Disks in a Pane
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Fri, 11 Apr 2008 01:40:54 -0400 (EDT)
- References: <ftkbd6$bf6$1@smc.vnet.net>
Hi, InDiskTest[pos_, Disk[c_, r_]] := Sqrt[#.#] &[pos - c] < r InDisk[pos : {_?NumericQ, _?NumericQ}, disks : {_Disk ..}] := Position[disks, d_Disk /; InDiskTest[pos, d]] DynamicModule[{disks, pos = {}, k, where = {}, shape}, disks = {Disk[{1, 1}, 0.5], Disk[{2, 2}, 0.5]}; EventHandler[ Dynamic[shape = disks; If[where =!= {}, k = where[[1, 1]]; shape[[k]] = shape[[k]] /. Disk -> Circle ]; Graphics[{MapThread[List, {{Red, Green}, shape}]}]], { "MouseDown" :> (where = InDisk[MousePosition["Graphics"], disks]) } ] ] ?? Regards Jens robert prince-wright wrote: > Can someone help me figure out how to use EventHandler > to evaluate an expression when one of many Disk[] > objects in a Graphics Pane is clicked. > > For example suppose I create a red and green disk in a > graphic: > > Graphics[{Red, Disk[{1, 1}, 0.5], Green, Disk[{2, 2}, > 0.5]}] > > Each disk is a separate and editable object in the > graphics pane. Can I therefore associate an Event with > a Mouseclick on each disk? To make matters simple lets > say the disk change color from Red to Yellow and Green > to Brown. > > > > > Robert Prince-Wright > Houston > TX, 77006 > USA > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com >