(*   This is the file MakeFramesMobius.m, written by

     Douglas N. Arnold  <dna@math.psu.edu>
     Department of Mathematics
     Penn State
     University Park, PA  16802
     
     January 1997, June 1997
*)
      
Needs["complexcurves`"]
Needs["Graphics`Colors`"]

(* This file makes an animation of a homotopy from the identity to
   a "generic" Mobius transformation, the homotopy passing always
   through Mobius transformations, showing the evolution of the image of
   a rainbow shaded rectangle.  The frames of the evolution are output
   as GIF files.
   
   The transformation is (z-I)/(2+I/Pi^4-Pi z).
*)

         (* STEP 1: DESCRIBE THE DESIRED ANIMATION *)
         
ll=-1- I;             (* lower left and upper right corners of *)
ur=-ll;               (*   the rectangle to be plotted *)

llplot=-2.5-2.5 I;    (* lower left and upper right corners of *)
urplot=-llplot;       (* plotting region *)

nframes=11;           (* number of frames in the animation *)

vlines=2400;          (* number of vertical lines (these have varying hue) *)

starthue=0;           (* starting and ending hues for the vertical lines *)
endhue=.9;            (*   (both should be in [0,1] ) *)

vthickness=.01;       (* thickness of the vertical lines *)

hlines=11;            (* number of horizontal grid lines to superimpose *)

hgridcolor=Gray;      (* color of the horizontal grid lines *)

hthickness=.008       (* thickness of the horizontal grid lines *)

vglines=11;            (* number of horizontal grid lines to superimpose *)

vgridcolor=Gray;      (* color of the horizontal grid lines *)

vgthickness=.008       (* thickness of the horizontal grid lines *)

bdrycolor=White;      (* color of the boundary *)

bdrythickness=.01     (* thickness of the boundary lines *)

pixels=400;            (* size of the image in pixels *)
 
prefix="mobius";      (* filename prefix *)

options =             (* general plot options *)
  {Background->Black, DefaultColor->White, AspectRatio->Automatic};


                     (* STEP 2: MAKE THE ANIMATION *)

curvelist = 
    Join[
      (* colored vertical lines *)
      Table[
        line@@Join[{Re[ll]+j(Re[ur]-Re[ll])/(vlines-1)+I Im[ll],
             Re[ll]+j(Re[ur]-Re[ll])/(vlines-1)+I Im[ur],
          PlotStyle->{{Thickness[vthickness],
                Hue[starthue + (endhue-starthue)j/(vlines-1)]}}},
          options],
        {j,0,vlines-1}],
      (* horizontal grid lines *)
      hlinearray@@Join[{ll,ur,hlines,
        PlotStyle->{{Thickness[hthickness],hgridcolor}}},
          options],
      (* vertical grid lines *)
      vlinearray@@Join[{ll,ur,vglines,
        PlotStyle->{{Thickness[vgthickness],vgridcolor}}},
          options],
      (* boundary *)
      {rectangle@@Join[{ll,ur,
        PlotStyle->{{Thickness[bdrythickness],bdrycolor}}},
          options]}
      ];

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

Table[
  Module[{t},(
    t=(i-1)/(nframes-1);
    Display[
      filename[prefix,i],
      showcurve[image[((1-t)#+t(#-I))/((1-t)+t(2+I/Pi^4-Pi#))&,curvelist],
      PlotRange->{{Re[llplot],Re[urplot]},{Im[llplot],Im[urplot]}},
      DisplayFunction->Identity],"gif",ImageSize->pixels])],
  {i,1,nframes}]
    
Print[StringJoin["-- frames written --"]]


