nil*_*ock 8 wolfram-mathematica
我想为Mathematica 3D图形添加交互性,而不是Manipulate,它很酷但有其局限性.想想Mathematica中四个立方体问题演示的四个例子,点击其中一个立方体就会旋转一个立方体.
问题.
是否有可能在Mathematica图形中捕获MouseEvents(例如使用Java类或其他?)
或者是使用Java然后从Java调用Mathematica建议路由?
或者(我希望不是)正在开发超出Mathematica应该做的交互式图形程序?
Sjo*_*ies 15
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})}]
}
]
]
Run Code Online (Sandbox Code Playgroud)
可以单独点击圆圈.分别为每个对象定义一个动作.
令人惊讶的是,这甚至适用于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})}]
}
]
]
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
825 次 |
最近记录: |