Making Animations and Flipbooks Carl Swenson Department of Mathematics Seattle University Introduction Students often consider school math to be an abstract set of symbols, formulas, algorithms, and witchcraft that has no roots in the real world. Graphic images are an important tool needed to teach mathematics well. These images provide needed links for the visual learner, and deepen the understanding of mathematics for all learners. With computer generated graphics we can show pendulums swinging, functions growing, and tires rolling. Mathematica, with its notebook format and animation control, is an ideal tool with which to create animations. Topics are abundant: in precalculus and calculus some of my animations include functions, the effect of changing a given coefficient in a polynomial, limits, the secant line becoming the tangent line as delta-x becomes small, the slopes of the tangent lines from the derivative function, Riemann sums, Taylor polynomial approximations, pendulums, cycloids and The Fundamental Theorem of Calculus. Today's students are more visually oriented and more visually sophisticated; we must pay attention to this and promote more visualization of mathematics. This paper will present the process through which I produce animations and flipbooks to illustrate mathematical concepts. It is my intent that others will be able to use some of my ideas, experiences, and Mathematica code to produce their own animations and graphic materials for students. Start with a need Although the reader may be impatient to write code and see animations, it is important to pause and consider what the purpose of the animation will be. My original work [Swenson, 1990] concentrated on the studentsU understanding of functions and designed a simple animation to help students move from a RpointwiseS understanding of function to an Racross-timeS understanding. This topic was suggested by Monk [Monk, 1988]. Monk has shown that most Calculus students have a R pointwiseS understanding of functions but only about half of them have an R across-timeS understanding. It is easy to misjudge our audience and get carried away with a more sophisticated view. By starting with something familiar to students you can exploit their understanding to create a deeper or a different understanding. Thus I presented the RpointwiseS student with a new experience designed to lead them to a deeper Racross-timeS understanding of a function. Create a simple model My first project was to create an animation showing a function being generated across-time by a series of function-points moving from left to right. A second early project in trigonometry needed a series of points moving around a circle. Each project required one basic graphic model that would be used as the basis for all the frames. Play with various ideas. Plot a function or create the first graphic image that will set the standard for the size of the frame. Before generating a set of frames, use a single cell output to test various graphics, functions, ranges, pointsize, color, and aspect ratio. Trial-and-error has been used to create the desired function and ranges. In the second code example the option AspectRatio is necessary to insure the roundness of the circle. These codes are used as a basis for the animations in Figures 1-3. (* function plot *) Plot[x^3-6x^2+9x+3, {x,0,4}, PlotRange->{{-1,5},{-1,10}}, PlotStyle->RGBColor[0,0,1]] (* circle and point graphics *) Show[ Graphics[ {Circle[{0,0},1], PointSize[.03],Point[{1,0}]}], AspectRatio->1] Make a prototype with iteration For, Do, or While loops generate short sequences as a prototype. At the trial-and-error stage new, subtle, and time-consuming problems can appear. Two examples are given below. In one example a wobble, only visible when running the animation, is caused by specifying only the x range and not both x and y range. The other example produces output only after turning the symbolic symbol Pi into a real value. [Pi is held as a symbolic value (Head[Pi] is Symbol) and therefore cannot be tested against a real variable value (Head[t] is Real).] Only four frames from each iteration are shown. In[1]:= (* iteration by For, b+= sets the step *) For[ b=.1, b<=4, b+=.25, Plot[x^3-6x^2+9x+3,{x,0,b}, PlotRange ->{{-1,5},{-1,10}}]] In[2]:= (* iteration by a Do loop *) Do[ Show[ Graphics[ {Circle[{0,0},1], {GrayLevel[.1], Disk[{Cos[t],Sin[t]},.04]}}], AspectRatio->1, PlotRange->{-1.1, 1.1}], (* should be {{-1.1, 1.1},{-1.1, 1.1}} *) {t, 0., 2Pi, Pi/10}] Out[2]:= In[3]:= (* iteration by a While, accumulates dots *) dots = {PointSize[.05]}; t=0. While[t<2Pi//N, (* t<2Pi will not work *) AppendTo[ dots, Point[ {Cos[t],Sin[t]}]]; Show[ Graphics[{Circle[{0,0},1], dots}], AspectRatio->1]; t+=Pi/10] Generalize and embellish We now concentrate on improving several drawbacks of the first prototype: the pointwise aspect of the function is not clearly shown, the x value could be better linked to f(x) in the graph, and the numeric data could be shown. An improved design features the parameters, including the function itself, in one accessible place at the beginning of the code. The code below inefficiently calculates each cell from scratch (see the Map[ Point, Table[...]] construction). If speed and efficiency are factors in generating the images, a growing list of points can be constructed with the AppendTo command as shown above. PointSize, Dashing, and Text location were all fine-tuned by trial-and-error with the loop temporarily set to one frame. In[4]:= (* pointwise to across-time function animation *) f[x_]:= x^3-6x^2+9x+3 (*define function*) xmin = -1; xmax = 4.5; ymin = 0; ymax = 8.0; (* axes ranges *) xlabel=SxS; ylabel=Sf(x)S (* axes labels *) start=0; stop=4; step=.25; (* Iterated copies: start/stopstep determines number of frames *) For[ b=start,b<=stop,b+=step, Show[ Plot[f[x],{x,xmin,b}, PlotRange->{{xmin,xmax},{ymin,ymax}}, AxesLabel -> {xlabel,ylabel}, DisplayFunction -> Identity ], (* points *) Graphics[ PointSize[.03],Point[{b,0}], Map[ Point, Table[{x,f[x]}, {x,start,b,step}] ] ], (* line and text *) Graphics[ Dashing[{.01}], Line[{{b,0},{b,f[b]}}], Text[ StringForm[Rf(``) =``S,b,N[f[b],3]], {xmin+2,ymax+.5},{-1,0}] ], DisplayFunction ->$DisplayFunction] ] Test and Version 2.0 Enhancement It is easy to assume your work is perfect, especially after 30 or more generations! It can indeed be technically correct but flawed for the audience. For example, using code similar to that above I constructed an animation showing the Fundamental Theorem of Calculus. It showed area accumulating under a quadratic function generating a cubic area function. Mathematicians saw the meaning immediately, but many students were left confused. They had a difficult time understanding the animation because the y -axis was being used to measure two different variables: the function value and the total area value. The original animation and the resulting changes are shown in Figure 5. Mathematica Version 2.0 solved many problems. It is now possible to put two (or more) graphics in one cell. The rectangular border defines a consistent size that can be cut out for flipbooks. The first, last and one middle frame of the animation is shown below. This article was prepared using a beta-version of Mathematica 2.0 which did not allow nesting a GraphicsArray object in another GraphicsArray object. Once the framed pairs were created as GraphicsArray objects, they could only be shown serially. In[5]:= (* The Fundamental Theorem of Calculus *) f[x_] = 3x^2-12x+9 integralf[x_] = Integrate[f[x],x] xmin = -1; xmax = 4.5; ymin = -4; ymax = 10.5 xlabel = RxS; ylabel = Rf(x)S start = .25; stop = 4; step = .25; inc = .05 (* function plot held for later display *) functionplot = Plot[ f[x], {x,xmin,xmax}, PlotRange ->{{xmin,xmax}, {ymin,ymax}}, AxesLabel ->{xlabel,ylabel}, PlotStyle ->{{Thickness[.007], RGBColor[0,0,1]}}, DisplayFunction->Identity] (* Holds display *) (* area plot coordinate system for later display *) areaplot= Plot[ 0,{x,xmin,xmax}, PlotRange ->{{xmin,xmax}, {ymin,ymax}}, AxesLabel ->{xlabel,SAreaS}, DisplayFunction ->Identity] (* make table of function plots, hold display *) tableplots1 = Table[ Show[ functionplot, Graphics[ Dashing[{.01}],RGBColor[0,1,0], Map[ Line, Table[{{x,0}, {x,f[x]}}, {x,start,b,inc}]]]],{b,start,stop,step}] (* area point plots, hold display *) tableplots2=Table[ Show[ areaplot, Graphics[ PointSize[.02],RGBColor[0,1,0], Point[{b,integralf[b]-integralf[start]}] ] ], {b,start,stop,step}] (* Display framed pairs *) Do[ Show[ GraphicsArray[ {{tableplots1[[i]]},{tableplots2[[i]]}}], Frame -> True, DisplayFunction -> $DisplayFunction ], {i,1,16}] (* Generate last frame with all area points *) Show[ GraphicsArray[ {{tableplots1[[16]]},{Show[tableplots2]}}], Frame -> True, DisplayFunction -> $DisplayFunction] Presentation It is easy to overlook presentation difficulties. For classroom animations, the overhead projection device must be powerful enough to operate with a screen panel display. I found I needed a dark room or a dark day. The overhead projection problem became worse when I decided to test a color version of the animation. Older color screen projection panels do not refresh the screen rapidly enough and the animation can be blurred. For animations, color was effective in drawing the correspondence of the area (green) to the (green) dot on the area plot. In producing flipbooks it is important that the frames be congruent. Mathematica 1.2 serially created graphics and to create cutout frames that were exactly equal in size, each frame was imported to a page layout program and dividers were added. Great effort was not rewarded; a nonuniform product resulted because errors in photocopying were up to one-sixteenth of a inch. This created variable sizes for the frames situated on the edge. In the example above the framing of a graphic cell insures that each cell has exactly the same size. Notebook animations are much better controlled with Version 2.0. The bottom scroll bar enables the user to move easily to any frame and thus by wiggling the scoll bar back and forth the animation wiggles. The Graph/Animation menu allows sub-loops of some frames or sets of frames can shown for a varying length of time. Packaging The code in the last animation became more complex, and it is at this time that attention to efficiency would pay off. Indeed it may even be demanded if you run out of memory. A problem that can be encountered on a Macintosh IIfx is to have the color density set to millions, thus creating huge files of several megabytes, and quickly exhausting memory. The Characteristics of the moniter selection in the Monitor file (Black&White, 4, 16, 256, or millions) will dramatically affect the size of the graphics file; the Gray levels or Color will not effect the size. Choose a setting that allows you to complete your task but one that does not squander resources. A final compacting of the file can be done by selecting the entire set of graphics cells and using Convert to Bitmap PICT. Although the size reduction varies, it is usually about 50%. It is also possible to generate an animation in pieces, converting each piece to bitmat. Once all the pieces are generated, start Mathematica with the kernel turned off and put them together into one notebook. Large Notebooks can be animated without a kernel or with MathReader. The best way to have a graphic set of cells ready for animation in a notebook is to nest and close the cells so that there is just one copy visible on the screen. For a flipbook, a title page should be constructed to make it look professional. Additionally an information sheet about the animation might be included as a second or as a last page. The code for a title page using version 2.0 control of font, face, and size is given below. To complete this flipbook make a page layout by manually cutting around the title page and the 17 previously generated frames. Tape them onto a standard (8 1/2 by 11) sheet. A print size reduction may be necessary to efficiently use the sheets; I used a print reduction by 80% and fit nine frames, three-by-three, onto a page. In[6]:= (* Title page for Fundamental Theorem flipbook *) title= Show[Graphics[ { Text[FontForm[ RTheS, {RTimes-BoldS,14.}],{1.75,9.0}], Text[FontForm[ RFundamental TheoremS, {RTimes-BoldS,14.}],{1.75,7.0}], Text[FontForm[ Rof CalculusS, {RTimes-BoldS,14.}],{1.75,5.0}], Text[FontForm[ RCarl SwensonS, {RTimes-BoldS,12.}],{1.75,2.0}], Text[FontForm[ RSeattle UniversityS, {RTimes-BoldS,12.}],{1.75,0.0}], Text[FontForm[ R1991S, {RTimes-BoldS,9.}],{1.75,-2.0}] }, PlotRange -> {{xmin,xmax},{ymin,ymax}}, DisplayFunction -> Identity ] ] (* Generate title frame *) Show[ GraphicsArray[ {{title}, {Show[{tableplots1[[16]],tableplots2}]}}], Frame->True, DisplayFunction -> $DisplayFunction] Figure 7: Title page for flipbook Other sources For big-budget Hollywood animations see Project Mathematics! and The Mechanical Universe Q available on video tape[3]. At the present time producing a video tape of Mathematica animations on a Macintosh is prohibitively expensive, but it will certainly become possible in the future. There are two books that have Mathematica code for animations. Wagon [4] has a superb chapter on cycloid, hypocycloid and epicycloid animation. One animation program answers the question, RWhat is the nature of the road on which a polygon will roll smoothly?S another is the Cycloid as Brachistochrone. A more recreational approach to using Mathematica including some animation ideas is presented by Gray and Glynn [5]. References [1] C. Swenson, Using animations and flipbooks, Proceedings of the Third Annual International Conference on Technology in Collegiate Mathematics, Addison-Wesley, 1990. [2] G.S. Monk, StudentsU Understanding of Functions in Calculus Courses, Humanistic Mathematics Network Newsletter, No.2, March 1988. Harvey Mudd College. [3] T. Apostal, et al, Project Mathematics!, California Institute of Technology, 1990. [4] S. Wagon, Mathematica in Action, W.H Freeman and Company, 1991. [5] T. Gray and J. Glynn, Exploring Mathematics with Mathematica, Addison-Wesley, 1991. About the Author Carl Swenson, Ph.D., is an Associate Professor of Mathematics at Seattle University. In addition he has taught at Haile Sellassie I University, Claflin College, and The Evergreen State College. His long standing interests are mathematics education and computers. As part of a recent sabbatical he developed and now has taught an upperdivision class, Mathematics using Computers, based on Mathematica. His hobbies include hanging out in Paris and New York.