2
$\begingroup$

I have the following animation that I wish to export as GIF

     ac = Table[Graphics[{EdgeForm[Black], LightGray, Polygon[{{0, 0}, {1/\[Lambda], 0},{1/[Lambda],\[Lambda]}, {0, \[Lambda]}} /. \[Lambda] -> t]}], {t, 1, 4,0.1}];
    Export["gif.gif", ac, "GIF","DisplayDurations" -> 0.25]

but suddenly at the end a black background starts to appear, as shown below. What may be the flaw ?

enter image description here

$\endgroup$
3
  • 3
    $\begingroup$ Why didn't you fix a PlotRange setting in your Graphics[]? $\endgroup$ Commented Jul 21, 2022 at 0:07
  • $\begingroup$ @J.M. I need it to stay the same height as it changes. $\endgroup$ Commented Jul 21, 2022 at 0:27
  • 1
    $\begingroup$ ...and that's exactly why you should have an explicit PlotRange setting! $\endgroup$ Commented Jul 21, 2022 at 0:31

1 Answer 1

4
$\begingroup$
  • One workaround is using ListAnimate
output = ListAnimate[ac];
Export["gif-1.gif", output, "DisplayDurations" -> 0.25, 
 "ControlAppearance" -> None]
  • I also recommend to set PlotRange.
ac = Table[
   Graphics[{EdgeForm[Black], LightGray, 
     Polygon[{{0, 0}, {1/λ, 
         0}, {1/λ, λ}, {0, λ}} /. λ ->
         t]}, PlotRange -> {{0, 2}, {0, 4.5}}, Axes -> True], {t, 1, 
    4, 0.1}];
Export["gif-2.gif", ac, "GIF", "DisplayDurations" -> 0.25]

enter image description here

$\endgroup$
1
  • $\begingroup$ Nice. ListAnimate is what I was looking for. Any idea about what may be causing the black background in my approach ? $\endgroup$ Commented Jul 21, 2022 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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