question on flicker and double buffering in Mathematica graphics
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
]
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开发者_Go百科 '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.
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.
精彩评论