20
$\begingroup$

I made the following animation, but the disks and the rectangle are shaking, breaking the smoothness of the motion. enter image description here

Here is a minimal example. If you look carefully you will see the disks are shaking.

tab = Table[ConstantArray[Cos[0.3* t], 3], {t, 2, 6, 0.02}];
l0 = 1;
show[x_] := 
 Block[{}, 
  Graphics[{Rectangle[{0, -.5}, {.5, .5}], 
    Rectangle[{5, -.5}, {5.5, .5}], 
    Table[Disk[{x[[i]] + i*l0, 0}, 0.2], {i, 3}]}, ImageSize -> 800]]
plots = Table[show[tab[[i]]], {i, 1, Length@tab, 1}];
Export["temp.gif", plots]

enter image description here

Please not the rectangles are still here, so I don't think it is a scaling issue. This is supported by the fact that specifying PlotRange does not change anything (ImagePadding -> None does not either).

 plots = Table[Show[show[tab[[i]]], PlotRange -> {{0, 5.5}, {-.5, .5}}, 
     PlotRangePadding -> None], {i, 1, Length@tab, 1}]

enter image description here

A comment suggested to change the frame rate; though less obvious, the shaking motion is still present:

  Export["temp.gif", plots, "DisplayDurations" -> 1/50.]

enter image description here

Please not the shaking is not introduced by Export, since it is also observed with ListAnimate@plots.

The question is, of course, how to prevent this shaking?

Interestingly, changing Disks to Point works, but I am looking for a more robust solution (in particular, Arrows also "shake" and can't be easily replaced...).

 show[x_] := Block[{}, Graphics[{Rectangle[{0, -.5}, {.5, .5}], 
   Rectangle[{5, -.5}, {5.5, .5}], PointSize[0.08], 
   Table[Point[{x[[i]] + i*l0, 0}], {i, 3}]}, ImageSize -> 800]]

The following animation is fine: there is no vertical jumps. enter image description here


Animations made with version: 11.0.0 for Linux x86 (64-bit) (July 28, 2016).


Using OSX and MMA 11.1, halirutan reduced the gap between the disks to better highlight the shaking motion:

enter image description here

Of course the motion should be smooth, but that's really not the case.

$\endgroup$
  • 1
    $\begingroup$ I guess problem will be solved by increasing the frame rate. Your animation is just 51 frame for ~5 sec of duration but normal video has 24 fps namely for smooth movements. $\endgroup$ – Rom38 Apr 11 '17 at 3:53
  • 1
    $\begingroup$ I don't see the problem on Win7 V11.1. Sometimes fixing PlotRange/ImagePadding and friends helps. $\endgroup$ – Kuba Apr 11 '17 at 6:17
  • $\begingroup$ the jump at the end is of couse because you arent doing an exact full cycle. $\endgroup$ – george2079 Apr 11 '17 at 11:52
  • 1
    $\begingroup$ I'm on V11.0.0.0 on OSX and I do not see the vertical jumping. Sounds like it might be Linux specific. $\endgroup$ – N.J.Evans Apr 12 '17 at 13:48
  • 1
    $\begingroup$ OSX and Mathematica 11.1 here. I change your animation a bit, putting the disks close together. It looks awful. $\endgroup$ – halirutan Apr 12 '17 at 18:24
1
$\begingroup$

One way to avoid rasterization rounding issues is to work directly with rasters and ImageCompose

r = 20
n = 5
dx = 50
wbar = 10
amp = 50
back = ImageCompose[
   Image[ConstantArray[
     1, {70, dx (n - 1) + 2 amp + 2 wbar  + 2 r + 1}]] ,
   ConstantArray[Image[ConstantArray[0, {50, wbar}]], 
    2] , {{wbar/2, 35} , {dx (n - 1) + 2 amp + (3/2) wbar  + 2 r + 1, 
     35}}];
frames = (ImageCompose[back, 
        ConstantArray[Image[1 - DiskMatrix[r]], n],
        Table[{# + r + 10 + dx i, 35}, {i, 0, 
          n - 1}]] &@ (amp (Sin[# +  Pi/2] + 1) )) & /@ 
   Range[ 0 , 2 Pi  , Pi/20];

Export["test.gif", frames]

enter image description here

enter image description here

combining with the spring graphics might be a challenge..

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.