关于 Mathematica 图形中的闪烁和双缓冲的问题

发布于 2024-11-29 04:45:31 字数 2576 浏览 1 评论 0原文

Mathematica 如何处理图形显示的双缓冲?是自动完成的吗?

我问的原因是,当我做一些动画时,根据动画速率,我注意到屏幕上的图形更新时出现烦人的闪烁。当我放慢速度时我可以减少这个。

我将在下面展示一个简单的例子来说明我的意思,并询问专家是否对如何减少显示的闪烁有建议。

此示例围绕圆绘制一个点。动画运行时您会注意到闪烁。即球的运动不平滑。当减慢速率时,闪烁就会减少。但我认为即使速率很高,也应该有办法减少闪烁吗?

Manipulate[
 (
  pt = {Cos[n], Sin[n]};
  Graphics[
   {
    {Blue, Thickness[0.01], Line[{{0, 0}, pt}]},
    {PointSize[.08], Red, Point[pt]}
    }, PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}}, ImageSize -> 200]
  ),

 Control[{{n, 0, "Run"}, 0, 1000, ControlType -> Trigger, 
   DisplayAllSteps -> True, ImageSize -> Tiny, AnimationRate -> 1, 
   AppearanceElements -> {"ProgressSlider", "ResetPlayButton", 
     "PauseButton", "StepLeftButton", "StepRightButton", 
     "ResetButton", "FasterSlowerButtons"}}],

 SynchronousUpdating -> True
 ]

在此处输入图像描述

所以我的问题是:事情应该是这样的吗?或者是否有一些技巧和提示可以用来使动画更新运行得更流畅(减少闪烁),即使速率未设置为“最佳”,Mathematica 是否在内部使用双缓冲来更新图形?

我在 Windows 7 64 位上使用 V 8.0.1。

谢谢

更新1 我想我的问题可能没有提出好。由于我没有直接使用 Animate,所以不能责怪 Mathematica。我现在使用 RunScheduledTask[] 来更新计时器,并且在每个计时器实例中,我在 Graphics 中制作新的绘图。很难用它来制作一个小例子来发布在这里,所以在上面,我只是使用了触发器。因此,在这种情况下我不能使用 RefreshRate,因为我现在实际上没有使用 Trigger。

我正在查看讨论更新屏幕的这些问题的不同网页,例如 页面 和其他,这就是我问的原因。

这是我现在正在制作的 CDF,用于制作双摆的动画,您可以看到,如果将 delta_t 设置得较大(这是找到的 ODE 数值解的每个间隔之间的时间),动画将显示在屏幕有很多闪烁(或者你喜欢使用的任何术语),重点是,用眼睛看并不容易,并且想找到我是否可以采取措施来防止这种情况。

这是CDF

您也可以使用鼠标改变摆锤的位置来查看闪烁的效果更大。

感谢您指出 RefreshRate,但看起来我无法在当前的实现中使用它,因为由于描述的问题,我不再使用触发器 这里

我想我现在只需要保持 delta_t 小。

更新2

这是我用来更新图形的代码部分

.......
Dynamic[Refresh[Graphics[
   {
    Line[{{0, 0}, bob1}],
    Line[{bob1, bob2}],
    {PointSize[.05], Red, Point[bob1]},
    {PointSize[.05], Red, Point[bob2]}
    }, graphicsOptions
   ], TrackedSymbols -> {update}, UpdateInterval -> v]] 
   (*updateInterval does not help with flicker*)
....................

上面的“更新”是由scheduledTask在我控制的每个time_interval上更新的变量。

更新

我想我展示了一个我看到的小程序,它也用 Java 制作了双摆动画,而且我认为它的闪烁比我做的要少得多,即使我以大约相同的速度运行我的程序。这是链接 所以

,我想我仍然有还有更多工作要做。我需要找到一种方法来减少这种闪烁效果。

How does Mathematica handle double-buffering for Graphics display? Is it done automatically?

The reason I am asking, is that when I do some animation, depending on the animation rate, I notice annoying flicker while the graphics is being updated on the screen. I can reduce this when I slow down the rate.

I will show a simple example of what I mean below, and ask if the experts have advice on how to reduce the flicker shown.

This example draws a point around a circle. You'll notice the flicker as the animation is running. i.e. the motion of the ball is not smooth. When slowing down the rate, the flicker is reduced. But I think there should be away to reduce the flicker even what the rate is high?

Manipulate[
 (
  pt = {Cos[n], Sin[n]};
  Graphics[
   {
    {Blue, Thickness[0.01], Line[{{0, 0}, pt}]},
    {PointSize[.08], Red, Point[pt]}
    }, PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}}, ImageSize -> 200]
  ),

 Control[{{n, 0, "Run"}, 0, 1000, ControlType -> Trigger, 
   DisplayAllSteps -> True, ImageSize -> Tiny, AnimationRate -> 1, 
   AppearanceElements -> {"ProgressSlider", "ResetPlayButton", 
     "PauseButton", "StepLeftButton", "StepRightButton", 
     "ResetButton", "FasterSlowerButtons"}}],

 SynchronousUpdating -> True
 ]

enter image description here

So my question is: Is this how things supposed to be? or are there tricks and hints one can use to make the animation update run more smoothly (reduce flicker) even if the rate is not set to 'optimal', and does Mathematica use double-buffering internally for updating graphics?

I am using V 8.0.1 on windows 7, 64 bit.

thanks

Update 1
I guess my question might not have been well posed. As I am not using Animate directly, so can't blame Mathematica foranything. I am using RunScheduledTask[] now to update a timer, and at each timer instance, I make new plot in Graphics. Was hard to make a small example using that to post here, so in the above, I just used Trigger instead. So, I can't use RefreshRate in this case since I am not actually using Trigger now.

I was looking at different web pages that talk about these issues of updating screen, such as this page and others, and that is why I asked.

Here is a CDF I am making now, to make animation of a double pendulum, and you can see, if you make the delta_t large (this is the time between each interval of the numerical solution to the ODE's found), the animation display on the screen has lots of flicker (or whatever term you like to use), the point is, it is not easy to look at on the eye, and wanted to find if something I can do to prevent this.

Here is the CDF

You can use also the mouse to change the position of the pendulum to see the effect of the flicker more.

Thanks for pointing out RefreshRate, but it does not look like I could use it in my current implementation as I am not using Trigger any more due to the problem as described here

I guess I just have to keep delta_t small for now.

update 2

This is section of the code I use to update the graphics

.......
Dynamic[Refresh[Graphics[
   {
    Line[{{0, 0}, bob1}],
    Line[{bob1, bob2}],
    {PointSize[.05], Red, Point[bob1]},
    {PointSize[.05], Red, Point[bob2]}
    }, graphicsOptions
   ], TrackedSymbols -> {update}, UpdateInterval -> v]] 
   (*updateInterval does not help with flicker*)
....................

The 'update' above is the variable which is updated by the scheduledTask at each time_interval which I control.

Update

I thought I show an applet I saw which also animate a double pendulum in Java, and I think it has much less flicker than the one I did, even when I run mine at about the same speed. Here is the link
http://www.myphysicslab.com/dbl_pendulum.html

So, I think I still have more work to do. I need to find a way to reduce this flickering effect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终难愈 2024-12-06 04:45:31

如果由低帧速率与每帧中相对较大的移动距离相结合产生的频闪效果就是您所说的“闪烁”,那么您可能希望尝试更高的 RefreshRate

Manipulate[(pt = {Cos[n], Sin[n]};
  Graphics[{{Blue, Thickness[0.01], 
     Line[{{0, 0}, pt}]}, {PointSize[.08], Red, Point[pt]}}, 
   PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}}, ImageSize -> 200]), 
 Control[{{n, 0, "Run"}, 0, 1000, ControlType -> Trigger, 
   DisplayAllSteps -> True, ImageSize -> Tiny, RefreshRate -> 50, 
   AnimationRate -> 3, 
   AppearanceElements -> {"ProgressSlider", "ResetPlayButton", 
     "PauseButton", "StepLeftButton", "StepRightButton", 
     "ResetButton", "FasterSlowerButtons"}}], 
 SynchronousUpdating -> True]

有趣的是,如果我设置刷新率-> 60 应该与我的 LCD 匹配,动画在一两分钟后停止播放,而实际上不应该。

If the strobe effect that comes from a low frame rate combined with a comparatively large distance moved in each frame is what you mean by "flicker" then you may wish to try a higher RefreshRate:

Manipulate[(pt = {Cos[n], Sin[n]};
  Graphics[{{Blue, Thickness[0.01], 
     Line[{{0, 0}, pt}]}, {PointSize[.08], Red, Point[pt]}}, 
   PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}}, ImageSize -> 200]), 
 Control[{{n, 0, "Run"}, 0, 1000, ControlType -> Trigger, 
   DisplayAllSteps -> True, ImageSize -> Tiny, RefreshRate -> 50, 
   AnimationRate -> 3, 
   AppearanceElements -> {"ProgressSlider", "ResetPlayButton", 
     "PauseButton", "StepLeftButton", "StepRightButton", 
     "ResetButton", "FasterSlowerButtons"}}], 
 SynchronousUpdating -> True]

Interestingly, if I set RefreshRate -> 60 which should match my LCD, the animation stops playing after a moment or two, when it should not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文