BeginPackage["GMT`GifMovieTool`"] (* File name: GifMovieTool.m *) (* Author: Oliver Knill, October 1996 *) (* With this package GifMovieTool.m you can *) (* put your animated MATHEMATICA pictures as GIF *) (* into your WEB page. This is a UNIX version. *) (* The reason for producing GIF animations is *) (* that Gif movies are relatively small files *) (* Usually the movie is smaller than a single *) (* PS file for a one Picture of the movie. A Web *) (* Browser like NETSCAPE can display the movie. *) (* The parameters can be modified to get a *) (* better or worse resolution. We recommend *) (* a small resolution like by default so that *) (* longer Mathematica Movies can be admired by *) (* surfers with relatively slow internet *) (* connections. *) (* This MATHEMATICA package requires to have *) (* executable programs PPMTOGIF and GIFMERGE *) (* available on your system. "GIFMERGE" can be *) (* obtained from *) (* http://www.iis.ee.ethz.ch/~kiwi/GIFMerge/ *) (* The program PPMTOGIF is part of the PPM *) (* which should be installed on your system. If *) (* this is not the case, you can download it *) (* from any good FTP-site with free UNIX stuff. *) (* Assume you have written a MATHEMATICA *) (* procedure Pict[k_] which renders or each *) (* number "k" a picture. Load this package and *) (* type "MakeGifMovie[Pict,File.gif,1,40]". It *) (* produces a movie with 40 pictures in a file *) (* in a file "File.gif" (Example1). Given two *) (* routines PictExe and StepExe. With *) (* DevelopGifMovie you can produce *) (* a movie while doing between each picture *) (* some calculations done in StepExe. (Example2) *) (* This package (July 31 1996) was written by *) (* OLIVER KNILL at Caltech *) (* Current address: Department of Mathematics *) (* University of Arizona, Tucson, AZ *) (* e-mail: knill@math.arizona.edu *) (* Some movies can be seen in my Homepage *) (* http://www2.math.arizona.edu/~knill *) (* Recent improvements by MAREK RYCHLIK *) (* from the University of Arizona in Oct 20 96 *) (* One can now give GIF image sizes as options *) (* in the procedures *) SaveGif::usage="Saves a Mathematica Picture as a gif file under a given name. The parameters height and width, the h and w resolution in rasterps are given as options as seen in example"; GifFileName::usage="GetFileName[128] renders back a string GMTfile128"; GifMerge::usage="GifMerge[MovieName] produces a GifMovie file with name MovieName from all the gif files beginning with GMT which are in the directory"; MakeGifMovie::usage="MakeGifMovie[P,Name,1,40] makes a movie with 40 pictures and function which renders for every natural number a Mathematica Picture"; DevelopGifMovie::usage="makes a movie while iterating a procedure"; Example1 ::usage="Make a Gif Movie using MakeGifMovie. After loading the package, type Example1. You get an animated GIF graphics using MakeGifMovie "; Example2 ::usage="Make a Gif Movie using DevelopeGifMovie. After loading the package, type Example2. You get an animated GIF graphics using DevelopGifMovie "; Options[MakeGifMovie]=Options[SaveGif]={ ImageWidthInches->2.0, ImageHeightInches->2.0, ImageWidthPixels->400, ImageHeightPixels->400} Options[DevelopGifMovie]=Options[SaveGif]={ ImageWidthInches->2.0, ImageHeightInches->2.0, ImageWidthPixels->400, ImageHeightPixels->400} Begin["`Private`"] SaveGif[PictName_, FileName_, opts___] := Block[ {winches, hinches, wpixels, hpixels}, {winches, hinches, wpixels, hpixels} = {ImageWidthInches, ImageHeightInches, ImageWidthPixels, ImageHeightPixels} /. {opts} /. Options[SaveGif]; Display[StringJoin["!rasterps -width ", ToString[winches], " -height ", ToString[hinches], " -w ", ToString[wpixels], " -h ", ToString[hpixels], " -format ppm>GMTpict.ppm"], PictName]; Run["ppmtogif GMTpict.ppm>GMTpict.gif"]; DeleteFile["GMTpict.ppm"]; CopyFile["GMTpict.gif",FileName]; DeleteFile["GMTpict.gif"]]; GetFileName[n_]:=Block[{u,v,w}, u=IntegerDigits[n]+48; v=ToCharacterCode["GMTfile"]; w=ToCharacterCode[".gif"]; FromCharacterCode[Join[v,u,w]]]; GifMerge[MovieName_]:=Block[{}, Run["gifmerge -l0 -1 GMTfile*.gif > GMTmovie.tmp"]; DeleteFile[FileNames["GMTfile*.gif"]]; CopyFile["GMTmovie.tmp",MovieName]; DeleteFile["GMTmovie.tmp"]]; MakeGifMovie[Pict_,MovieName_,FirstN_,LastN_,opts___]:= Block[{}, Do[SaveGif[Pict[i],GetFileName[1000+i],opts],{i,FirstN,LastN}]; GifMerge[MovieName]]; DevelopGifMovie[MovieName_,NumberOfIter_,opts___]:= Block[{}, Do[SaveGif[PictExe,GetFileName[1000+i],opts]; StepExe,{i,NumberOfIter}]; GifMerge[MovieName]]; Example1:=Block[{}, P=N[Pi]; WaveP[k_]:=Plot3D[Sin[3x-2P k/20] Cos[y-2P k/20],{x,0,5},{y,0,5}, Boxed->False, Axes->False,PlotPoints->20, PlotRange->{-1,1},DisplayFunction->Identity]; MakeGifMovie[WaveP,"BigMovie.gif",1,20, ImageWidthInches->4.0, ImageHeightInches->4.0, ImageWidthPixels->800, ImageHeightPixels->800]]; Example2:=Block[{},S={0.211234234,0.4555456234234}; PictExe:=Show[Graphics[{Hue[S[[2]]],Disk[S,0.04]}, DisplayFunction->Identity, Frame->True, Ticks->False, PlotRange->{{0,1},{0,1}},AspectRatio->1]]; StepExe:=Block[{},S=Mod[{{2,1},{1,1}}.S,1]]; DevelopGifMovie["Cat.gif",20, ImageWidthInches->2.0, ImageHeightInches->2.0, ImageWidthPixels->200, ImageHeightPixels->200]]; End[] EndPackage[]