1

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.

Community
  • 1
  • 1
Nasser
  • 12,849
  • 6
  • 52
  • 104
  • With your example, on mma7, I don't see flicker per se. There is of course a strobe quality to the animation due to the distance moved in each frame, and there is also a judder, presumably because the frame rate is not synchronized to the vertical refresh rate of the screen. What precisely are you concerned with? – Mr.Wizard Aug 12 '11 at 21:37

1 Answers1

1

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.

Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
  • Thanks for the reply. I am not familiar with the term strobe. But looked it now, I guess yes, that is what I mean. The animation I have is not smooth on the eye when I have delta_t too large, and was looking for a way to avoid this. Please see update 1. – Nasser Aug 12 '11 at 23:07
  • @Nasser - This is an issue I've struggled with as well, so thanks for asking... Have you tried UpdateInterval? (I think there may also be a global option related to how dynamics refresh, but can't remember it exactly.) Also, I seem to recall reading somewhere that refresh rates for LCD's are usually slightly less than 60. The number is usually rounded up when presented by the OS. – telefunkenvf14 Aug 12 '11 at 23:30
  • Yes, I actually tried UpdateInterval, but does not help. Please see update 2 for the section of code I have that draws the graphics. – Nasser Aug 12 '11 at 23:42