7
$\begingroup$

I have the following code:

g[ t_, OptionsPattern[{ θ -> (0 &), u -> ({0, 0, 1} &), v -> ({0, 0, 0} &)}] ] := Graphics3D[{ Arrow[{{0, 0, 0}, {5, 0, 0}}], Arrow[{{0, 0, 0}, {0, 5, 0}}], Arrow[{{0, 0, 0}, {0, 0, 5}}], Translate[ Rotate[{ Cuboid[{-1, -1, -1}, {1, 1, 1}],Arrow[{{0, 0, 0}, {5, 0, 0}}], Arrow[{{0, 0, 0}, {0, 5, 0}}],Arrow[{{0, 0, 0}, {0, 0, 5}}] }, OptionValue[θ][t], OptionValue[u][t]], OptionValue[v][t]] }, Lighting -> {{"Ambient", White}}, Boxed -> False, ViewPoint -> {2.82, 1.61, 1.20}, PlotRange -> {{-5, 5}, {-5, 5}, {-2, 7}} ] θf := Function[t, 0.5 Sin[t]]; uf := Function[t, {Sin[t], Cos[t]^2, Sin[t] Cos[t]}]; Animate[g[t, θ -> θf, u -> uf], {t, 0, 2 π}] tt = Table[ g[t, θ -> θf, u -> uf], {t, 0, 2 π, 2 π/100} ]; Export[NotebookDirectory[] <> "ms.gif", tt] 

but the quality of the animated GIF obtained is poor. How can I improve it? This is an example of a frame of the image:

enter image description here

Moreover, when the Export run, it in some way invalidates the Animation frame. Why? I mean that the running animation becomes the source code as in the following image. I also noted that g comes back to color blue, as if it was undefined.

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks, please add your version and OS info. $\endgroup$ Commented Feb 25, 2017 at 10:47
  • $\begingroup$ @Kuba: Mathematica Version Number 11.0.0.0, Platform: Mac OS X x86 (32-bit, 64-bit kernel). Operating system: OS X El Capitan 10.11.6. $\endgroup$ Commented Feb 25, 2017 at 10:52
  • 1
    $\begingroup$ For the second part of the question: g turning blue again indicates a kernel crash. I don't see this problem. I suggest you upgrade to 11.0.1. It is almost always a good idea to upgrade to point releases. They fix bugs. $\endgroup$ Commented Feb 25, 2017 at 12:12
  • $\begingroup$ @Szabolcs: thanks for the suggestion. $\endgroup$ Commented Feb 25, 2017 at 14:51

1 Answer 1

6
$\begingroup$

Mathematica is not good at creating beautiful and small gifs. It won't reach the quality you can can with e.g. ImageMagick's convert. Therefore, I suggest you export your images as png

Table[Export[ "~/tmp/imgs/" <> ToString[PaddedForm[i, 3, NumberPadding -> {"0", "0"}]] <> ".png", tt[[i]]], {i, Length[tt]}] 

and then you call something along the lines

convert -delay 1x15 imgs/* +dither -layers optimize out.gif 

in a terminal

enter image description here

I have to admit, that for this particular example, the gif created by Mathematica does look good as well. The file size, however, is larger by almost a factor of 2.

$\endgroup$
1
  • $\begingroup$ Thanks for the answer, I will try. $\endgroup$ Commented Feb 28, 2017 at 20:23

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.