I have created a list (listA) that specifies disks based on color, center point, and radius:
(* Define disks based on (i) color, (ii) center point, and (iii)
radius. listA is a list of such disks. *)
listA = {
{Red, {0, 0}, 0.5},(* object 1 *)
{Blue, {1, 1}, 0.75}(* object 2 *)
};
I have also defined a function displayList to display the disks with Graphics:
(* Create a function to plot the disks using Graphics. *)
displayList[list_List] := Module[{},
Graphics[{
list[[1, 1]], Apply[Disk, list[[1, 2 ;; 3]]],
list[[2, 1]], Apply[Disk, list[[2, 2 ;; 3]]]
}
, Frame -> True, PlotRange -> {{-2, 2}, {-2, 2}}]
];
Applying displayList to listA gives graphical output:
displayList[listA]
I would like to make the disks "clickable" -- I would like the disks' color to (dynamically) change when the user clicks on the disks.
Specifically, I want the following:
When the user clicks on the red disk (i.e., the disk of radius 0.5 centered at
{0, 0}),listAis updated so thatlistA[[1, 1]]changes fromRedtoBlue; anddisplayList[listA]is automatically reevaluated so that the disk is now displayed as blue.When the user clicks on the blue disk (i.e., the disk of radius 0.75 centered at
{1, 1}),listAis updated so thatlistA[[2, 1]]changes fromBluetoRed; anddisplayList[listA]is automatically reevaluated so that the disk is now displayed as red.
How should I go about approaching this problem? Should I think about defining a Locator for each disk?


ClickPane,Button,EventHandlerandDynamicin general. $\endgroup$