Possible Duplicate:
Wrapping EventHandler by Table
I am running Mathematica 7. However, I am new to using Dynamic
, DynamicModule
, EventHandler
, and the like.
I would like to create a Graphics
object containing numDisks
Disk
objects, where numDisks
is a positive integer. I would like each of the Disk
objects to be Red
, Green
, or Blue
. The default color is Red
, but if a disk is clicked, that disk goes to the next color, cyclically (Red
-->Green
-->Blue
-->Red
-->...). Is it possible to accomplish this using a DynamicModule
and multiple EventHandler
declarations?
I have tried the following. This code generates numDisks
disks in a row. When the user clicks anywhere within the Graphics
box, the color of all three disks changes to the next color in the sequence.
radius = 1;
numDisks = 3;
DynamicModule[{col = Red},
EventHandler[
Graphics[
Table[{Dynamic[col], Disk[{2.5*(i - 1), 0}, radius]}, {i, 1,
numDisks}],
PlotRange -> All],
{"MouseClicked" :> (col =
col /. {Red -> Green, Green -> Blue, Blue -> Red})}]
]
However, what if I would like each of the numDisks
Disk
objects to have its own color, which can be changed independently of that of all of the other Disk
objects? Is this possible? Can this be accomplished somehow using multiple EventHandler
declarations? Thanks for your time.