4

I'm using a dynamic module to rotate a Graphics3D at a certain rate:

autoRotate[gr_Graphics3D, rate_: 5] := 
 DynamicModule[{vp, va, vv, vc}, {vp, va, vv, vc} = 
   gr~AbsoluteOptions~#~OptionValue~# &@{ViewPoint, ViewAngle, 
     ViewVertical, ViewCenter};
  Overlay[{Show[gr, SphericalRegion -> True, ViewPoint -> Dynamic[vp],
      ViewAngle -> Dynamic[va], ViewVertical -> Dynamic[vv], 
     ViewCenter -> Dynamic[vc]], 
    Show[gr, SphericalRegion -> True, Boxed -> False, 
     ViewPoint -> 
      Dynamic[RotationMatrix[Clock[2 \[Pi], rate], vv].vp], 
     ViewAngle -> Dynamic[va], ViewVertical -> Dynamic[vv], 
     ViewCenter -> Dynamic[vc]]}, All, 1]]

And it works great. But now, I want to export the produced dynamic graphics object as a gif or mp4. How can I change the function definition to export as a gif?

Nico A
  • 3,634
  • 1
  • 15
  • 28
  • For generating animations, I usually generates a list of frames with Table function, and I export the gif as Export["animation.gif",framesList]. This doesn't answer exactly to your question, but I hope it may be of some help if you don't find a more straightforward solution :D – Fraccalo Jun 07 '18 at 16:06
  • https://mathematica.stackexchange.com/q/27202/5478 – Kuba Jun 07 '18 at 16:37

1 Answers1

5

Below ImagePadding -> 30 in the 3D graphic ensures that the rotation doesn't affect the size of the graphic. I'm not sure thats necessary for your graphic.

autoRotate[gr_Graphics3D, i_] := Module[{vp, va, vv, vc}, {vp, va, vv, vc} = 
 gr~AbsoluteOptions~#~OptionValue~# &@{ViewPoint, ViewAngle, ViewVertical, ViewCenter};
 Overlay[{Show[gr, SphericalRegion -> True, ViewPoint -> vp, ViewAngle -> va,
                                         ViewVertical -> vv, ViewCenter -> vc], 
  Show[gr, SphericalRegion -> True, Boxed -> False, ViewPoint -> RotationMatrix[i, vv].vp,
    ViewAngle -> va, ViewVertical -> vv, ViewCenter -> vc]}, All, 1]]

graphic = Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> "Rainbow",
                 Mesh -> None, ImagePadding -> 30];

frames = Table[Rasterize[autoRotate[graphic, i], "Image"], {i, 0, 2 π - #, #}] &[2 π/160];

Export["ani.gif", frames, "AnimationRepetitions" -> ∞, "ColorMapLength" -> 64,
 "DisplayDurations" -> ConstantArray[1/18, Length[frames]], Dithering -> "FloydSteinberg"]

Coolwater
  • 20,257
  • 3
  • 35
  • 64