(*   This is the file homotopyframes.m, written by
 
     Douglas N. Arnold  <dna@math.psu.edu>
     Department of Mathematics
     Penn State
     University Park, PA  16802
     
     January 1997

     Updated June 1, 1997 to output GIF files using the "gif" format
     argument to Display introduced in Mathematica 3.0.
*)
      
(* This package defines the function homotopyframes to depict the linear
   homotopy between two complex functions via an animation.  For more
   information see the usage message.

   Example of usage:  to better understand the operation of the function
   z^2 we watch a rectangle in the right half plane deform as we
   homotope from the identity to z^2:
   
   curvelist = linearray[-1.5I,1.5+1.5I,11,6,
     PlotStyle->{{Thickness[.008],RGBColor[1,1,0]}},
     Background->GrayLevel[0],
     DefaultColor->GrayLevel[1],
     AspectRatio->Automatic];
   f1[z_]:=z
   f2[z_]:=z^2
   nframes=11
   pixels=400
   prefix="z2"
   homotopyframes[f1,f2,curvelist,11,400,prefix,PlotRange->{{-4,4},{-4,4}}] 


   Douglas N. Arnold, dna@math.psu.edu, 1/1997
*)

BeginPackage["homotopyframes`","complexcurves`"]

homotopyframes::usage =
"If f1 and f2 are complex-valued functions of a complex
variable, curvelist is a list of curves in the complex plane
of the form curve[g[t],{t,a,b},options...], nframes is an
integer greater than 1, and opts are options to showcurve, then
homotopyframes[f1,f2,curvelist,nframes,resolution,prefix,showopts...]
creates the frames of an animation depicting the linear homotopy between
f1 and f2 by showing the evolution of the image of the given list of
curves in nframes frames.  Zero or more options to showcurves may be
given.  The frames are written as GIF files.  The argument pixels, which
can be a single number or a list of 2 numbers, specifies the number of
pixels in the image.  The files will be named prefix0001.gif,
prefix0002.gif, ..., with the specified prefix."

Begin["`private`"]

filename[prefix_,number_] := StringJoin[
  prefix,ToString[PaddedForm[number,3,NumberPadding->{"0",""}]],".gif"]

homotopyframes[f1_,f2_,curvelist_,frames_,pixels_,prefix_,showopts___] :=
  Table[ Display[filename[prefix,1+(frames-1)s],
  showcurve[image[((1-s)f1[#]+s f2[#])&,curvelist],showopts,
  DisplayFunction->Identity],"gif",ImageSize->pixels],{s,0,1,1/(frames-1)}]

End[]
EndPackage[]
