(*
   This mathematica file creates the files exponential1.anim
   and exponential2.anim to illustrate the definition of e as the
   number whose associated exponential function has derivative of
   1 at 0.

   These animate the graph of y=a^x with a as the animation parameter.
   Using manual frame control (e.g., via a slider), this gives a way
   to vary a manually and display the changing graph.
   
   The first animation lets a range from .1 to 10 and shows the
   graph on [-2,2]x[0,10].  The second animation shows a smaller
   range of a and plots the graph on [-1,1]x[0,2].  The line with
   slope 1 through (0,1) is shown as well.  By adjusting a we can
   make this line a tangent to the graph of y=a^x.  Of course this
   happens when a=e.

   Note: It is advisable to compress the animation files--they are big, but
   compress a lot).

   Sample viewing command:

     motifps exponential1.anim

   Douglas N. Arnold, 10/11/94

   Douglas N. Arnold  <dna@math.psu.edu>
   Department of Mathematics
   Penn State
   University Park, PA  16802

   Online documentation related to this file can be found at WWW URL
   http://www.math.psu.edu/dna/graphics.html.*)

BeginPackage["Exponential`", "Graphics`Animation`", "Graphics`Colors`"]

Begin["Private`"]

(* Describe the individual semiframes. *)

g[s_] := {s,{Gray,Thickness[0.001]}}
gridspec = {Table[g[s],{s,-2,2,.5}],Table[g[s],{s,0,10,2}]};
gridspec0 = {Table[g[s],{s,-1,1,.5}],Table[g[s],{s,0,2,.5}]};

expplot[s_]:= Plot[Exp[s x],{x,-2,2},
  PlotRange->{{-2,2},{0,10}},
  PlotStyle->{{Thickness[.01],Green}},
  Background->Black,DefaultColor->White,
  DefaultFont->{"Helvetica-Bold",24},
  GridLines->gridspec,
  MaxBend->5,
  Epilog->{Yellow,Text["y=a",Scaled[{.54,1.125}],{1,0}],
                  Text["x",Scaled[{.54,1.175}],{-1,0}],
                  Text["a = ",Scaled[{.4,-.25}],{1,0}],
                  Text[PaddedForm[N[Exp[s]],{4,2}],Scaled[{.4,-.25}],{-1,0}] },
  DisplayFunction->Identity]
  
expplot0[s_]:= Plot[Exp[s x],{x,-2,2},
  PlotRange->{{-1,1},{0,2}},
  PlotStyle->{{Thickness[.01],Green}},
  Background->Black,DefaultColor->White,
  DefaultFont->{"Helvetica-Bold",18},
  GridLines->gridspec0,
  MaxBend->5,
  Ticks->{{-1,-.5,0,.5,1},{0,.5,1,1.5,2}},
  AspectRatio->1,
  Epilog->{Yellow,
    Text[FontForm["y=a",{"Helvetica-Bold",24}],Scaled[{.2,.82}],{1,0}],
    Text["x",Scaled[{.22,.835}],{-1,0}],
    Text[FontForm["a = ",{"Helvetica-Bold",24}],Scaled[{.7,.1}],{1,0}],
    Text[FontForm[PaddedForm[N[Exp[s]],{4,2}],{"Helvetica-Bold",24}],
          Scaled[{.7,.1}],{-1,0}]},
  Prolog->{Magenta,Thickness[.01],Line[{{-1,0},{1,2}}] },
  DisplayFunction->Identity]
  
(* Create the animations. *)
smin=-2.3;
smax=2.3;
nframes=20;
delta = (smax-smin)/nframes;
ShowAnimation[Table[expplot[smin + n delta],{n,0,nframes}],
  AnimationFunction->(DisplayAnimation["exponential1.anim",#]&)];

Print["-- wrote file exponential1.anim --"]

(* These lines rasterize each frame separately to ppm format.  They can
   be used to create an MPEG animation file. *)
(* 
writetofile[i_] := StringJoin["!rasterps -format ppm > /tmp/graphics/exp1.",
  ToString[PaddedForm[i,3,NumberPadding->{"0",""}]],".ppm"]
Table[ Display[writetofile[n+1],expplot[smin + n delta]],{n,0,nframes}]
Print["-- rasterized frames from exponential1 --"]
*)

smin=0;
smax=1.67;
nframes=20;
delta = (smax-smin)/nframes;
ShowAnimation[Table[expplot0[smin + n delta],{n,0,nframes}],
AnimationFunction->(DisplayAnimation["exponential2.anim",#]&)];

Print["-- wrote file exponential2.anim --"]

(* These lines rasterize each frame separately to ppm format.  They can
   be used to create an MPEG animation file. *)
(*
writetofile[i_] := StringJoin["!rasterps -format ppm > /tmp/graphics/exp2.",
  ToString[PaddedForm[i,3,NumberPadding->{"0",""}]],".ppm"]
Table[ Display[writetofile[n+1],expplot0[smin + n delta]],{n,0,nframes}]
Print["-- rasterized frames from exponential2 --"]
*)
End[] (* end of context private *)

EndPackage[]

