2
$\begingroup$

I am trying to generate a vector graphics video in Mathematica. I stumbled upon SWF format (PNG are raster images which I'm not interested in). SWF format works fine for me but the axes and the numbers are still in raster.

Following is the minimal code in Mathematica

m = Manipulate[
  Plot3D[Sin[x y + a], {x, 0, 6}, {y, 0, 6}, Mesh -> False, 
   ColorFunction -> "StarryNightColors"], {a, 0, 4}]

Export["C:\\animated curves\\image-.swf", m, 
 "Scalable" -> True, "ControlAppearance" -> None, 
 ImageResolution -> 300]

and to view in $\LaTeX$

\documentclass{beamer}
\usepackage{media9}
\begin{document}
      \begin{frame}
        \begin{center}
          \includemedia[activate=onclick, width=0.5\textwidth]
          {\includegraphics{image-1.png}}{image-.swf}  % generate image-1.png too
        \end{center}
      \end{frame}
    \end{document}

I could see a long list in $ExportFormats, which Mathematica supports. However, there are not a handful of vector-graphics format for which "VideoFrames" works in Export. For instance

Export["C:\\Users\\Hawk\\Desktop\\animated curves\\image-.svg", m, "VideoFrames"];

generates following warning

Export::imgseqfmt: SVG is not an export format supported by "VideoFrames." >>

Similar warning appear for EPS format. If there might exist a better solution than SWF from the big pool available in Export, please let me inform.

$\endgroup$
  • 1
    $\begingroup$ perhaps Export individual files and use an extrnal tool to assemble $\endgroup$ – george2079 Dec 7 '15 at 12:47
  • 2
    $\begingroup$ swftools.org $\endgroup$ – george2079 Dec 7 '15 at 12:53
  • 1
    $\begingroup$ Having tried it your first Export works fine (I used Table instead of Manipulate ). Unfortunately the whole thing appears to be rasterized. You cannot export a single frame as swf so strike my earlier comments. $\endgroup$ – george2079 Dec 7 '15 at 14:43
  • 2
    $\begingroup$ my next thought is to export each frame as pdf and use swftools on that (You will I think need yet another tool to assemble the pdf's into a single document.) $\endgroup$ – george2079 Dec 7 '15 at 14:52
0
$\begingroup$

Code:

ManToGif[man_, name_String, step_Integer] :=
 Export[name <> ".gif",
  Import[
    Export[name <> Which[$OperatingSystem == "MacOSX", ".mov", $OperatingSystem == "Windows", ".avi"],
     man],
    "ImageList"][[1 ;; -1 ;; step]]
  ]

Example use:

   man = Manipulate[ContourPlot[
        q1/Norm[{x, y} - p[[1]]] + q2/Norm[{x, y} - p[[2]]], {x, -2,
         2}, {y, -2, 2}, Contours -> 20, PlotRangePadding -> 0,
        Frame -> False, PlotPoints -> 40, ImageSize -> 230,
        ColorFunction -> "DarkRainbow"], {{q1, -1}, -3, 3}, {{q2, 2}, -3,
        3}, {{p, {{-1, 0}, {1, 0}}}, {-1, -1}, {1, 1}, Locator},
       Deployed -> True, FrameMargins -> 0];

Result:

ManToGif[man, "charge", 2]

Reference

| improve this answer | |
$\endgroup$
  • 4
    $\begingroup$ Still a raster format, though (if I understand the OP correctly, a flash-like vector-based animation is desired). $\endgroup$ – Yves Klett Dec 7 '15 at 12:48

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