EventHandler可用于捕获各种鼠标事件(鼠标向上,鼠标向下,鼠标点击,鼠标拖动)。使用MousePosition添加一些智能。
实施例:
DynamicModule[{col1 = Green, col2 = Blue}, Graphics[
{
EventHandler[
Dynamic[{col1, Disk[]},
ImageSize ->
Tiny], {"MouseClicked" :> (col1 =
col1 /. {Red -> Green, Green -> Red})}],
EventHandler[
Dynamic[{col2, Disk[{1, 1}]},
ImageSize ->
Tiny], {"MouseClicked" :> (col2 =
col2 /. {Blue -> Yellow, Yellow -> Blue})}]
}
]
]
圆圈可以独立地点击。分别为每个对象定义一个动作。
令人惊讶的是,这甚至适用于3D图形:
DynamicModule[{col1 = Green, col2 = Blue},
Graphics3D[
{
EventHandler[
Dynamic[{col1, Sphere[]},
ImageSize ->
Tiny], {"MouseClicked" :> (col1 =
col1 /. {Red -> Green, Green -> Red})}],
EventHandler[
Dynamic[{col2, Sphere[{1, 1, 1}]},
ImageSize ->
Tiny], {"MouseClicked" :> (col2 =
col2 /. {Blue -> Yellow, Yellow -> Blue})}]
}
]
]
惊人。谢谢。 – 2011-05-31 15:32:06
@ ndroock1感谢您接受我的回答。下一次您可能再等一会以获得更多回应。 – 2011-05-31 15:49:47
Sjoerd,我已经为此投了票,但我会再次投票更新。我从来没有见过,可旋转和所有。 :-) – 2011-05-31 22:51:28