RE: Re: How to animate?
- To: mathgroup at smc.vnet.net
- Subject: [mg38540] RE: [mg38529] Re: How to animate?
- From: "David Park" <djmp at earthlink.net>
- Date: Tue, 24 Dec 2002 06:40:37 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
When I tried Borut's solution it produced a series of successive frames in place. But there was a blank screen in between each frame so it produced more a flashing effect than a true animation. So I wanted to try producing all the frames in a side notebook (which I could make Invisible) closing up the group of cells, then reading them and writing them back to the main notebook. However, I find it very difficult to NotebookRead the cells from the side notebook. Here is a simpler example in which I just produce a single plot in the side notebook. The following is the cell that makes the plot and selects the generated graphics cell. (I couldn't succeed in selecting the graphics cell from the main notebook.) sninput = Cell[BoxData[MakeBoxes[ Plot[Sin[x], {x, 0, 2\[Pi]}]; SelectionMove[sn, All, GeneratedCell]]], "Input"]; The following code, all in one cell, creates the side notebook, writes the plot statement into it, and evaluates it. But Mathematica fails to read the graphics notebook and write it back to the main notebook. sncells is just an empty list. NotebookClose[sn]; sn = NotebookCreate[Visible -> True, WindowSize -> {550, 500}, WindowMargins -> {{700, Automatic}, {Automatic, 100}}]; en = EvaluationNotebook[]; NotebookWrite[sn, sninput] SelectionMove[sn, Previous, Cell] SelectionEvaluate[sn]; sncells = NotebookRead[sn]; NotebookWrite[en, sncells] If you look at the side notebook you will see that the graphics cell is still selected. If I now repeat the last to commands in a separate cell... sncells = NotebookRead[sn]; NotebookWrite[en, sncells] ...it works. When I was trying this on a set of animation frames, it appeared that Mathematica attempted to NotebookRead and NotebookWrite before the cells were completely rendered and selected. I tried a Pause after SelectionEvaluate but that didn't work. How can I write a single set of commands in one cell that will read the graphics cell and transfer it to the main notebook? David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Borut L [mailto:gollum at email.si] To: mathgroup at smc.vnet.net Hi, A similar, but effectively different aproach would be to first generate the frames and then subsequently displaying each new frame and deleting the previous one. It's a solution by Omega Consulting dating 27. februar 2002 7:05 (SUBJECT "Re: Animation in one frame?"). It is always wise to look for past discussion on MathSource. GraphicsCell[gr_] := Cell[GraphicsData["PostScript", DisplayString[gr]],"Graphics"] ReplaceGraphic[gr_] := Module[{nb=EvaluationNotebook[]}, SelectionMove[nb, All, GeneratedCell]; NotebookWrite[nb, GraphicsCell[gr]] ] AnimateInPlace[{first_, rest___}] := (CellPrint[GraphicsCell[first]]; Scan[ReplaceGraphic, {rest}]) try AnimateInPlace[frames1] where frames1 are images created by David Park below. bye, Borut * Excerpt from Park's reply | versus about 13 seconds to produce the set in the first place. So it is not | perfect but maybe it will be good enough - or maybe somebody will suggest a | better method. "David Park" <djmp at earthlink.net> wrote in message news:au0riv$oo2$1 at smc.vnet.net... | Christopher, | | I like this question because now I have learned how to do something new. | | The following function is in the DrawGraphics package at my web site. I copy | it out here for anyone to use. | | DoShow[args1___, DisplayFunction -> _, args2___] := | Show[args1, DisplayFunction -> $DisplayFunction, args2]; | DoShow[args___] := Show[args, DisplayFunction -> $DisplayFunction] | | Now we make the frames for your animation without display. I increased the | number of plot points. It takes a little time. | | frames1 = | Table[ Plot3D[ BesselJ[0, Sqrt[x^2 + y^2] + t], | {x, -10, 10}, {y, -10, 10}, Axes -> False, | PlotPoints -> 30, | PlotRange -> {-0.5, 1.0}, | DisplayFunction -> Identity ], | {t, 0, 8} ]; | | Now we use the following commands to quickly display all the frames, close | them up and run the animation. All the frames are shown for about 1 second | versus about 13 seconds to produce the set in the first place. So it is not | perfect but maybe it will be good enough - or maybe somebody will suggest a | better method. | | DoShow /@ frames1; | SelectionMove[EvaluationNotebook[], All, GeneratedCell] | FrontEndTokenExecute["OpenCloseGroup"]; Pause[0.01]; | FrontEndExecute[{FrontEnd`SelectionAnimate[200, AnimationDisplayTime -> 0.1, | AnimationDirection -> Forward]}] | | The Pause command was included to guarantee that the cell group is closed | before the animation starts. However I find that there is a bug in Pause in | that it always pauses for 1 second even though it should handle smaller time | intervals. | | David Park | djmp at earthlink.net | http://home.earthlink.net/~djmp/ | | From: Christopher R. Carlen [mailto:crcarle at sandia.gov] To: mathgroup at smc.vnet.net | | | Hi: | | I'm using 4.1.0 on Linux | | I have been reading in section 1.9.12 about animating graphics. I don't | seem to be able to get the example to work. | | If I input: | | Table[ Plot3D[ BesselJ[0, Sqrt[x^2 + y^2] + t], | {x, -10, 10}, {y, -10, 10}, Axes -> False, | PlotRange -> {-0.5, 1.0}, | DisplayFunction -> Identity ], | {t, 0, 8} ] // Short | | Then I input: | | ShowAnimation[%] | | Mathematica just outputs: | | ShowAnimation[{\[SkeletonIndicator]SurfaceGraphics\[SkeletonIndicator], \ | \[SkeletonIndicator]SurfaceGraphics\[SkeletonIndicator], \ | \[SkeletonIndicator]SurfaceGraphics\[SkeletonIndicator], \ | \[SkeletonIndicator]SurfaceGraphics\[SkeletonIndicator], \ | \[SkeletonIndicator]SurfaceGraphics\[SkeletonIndicator], \ | \[SkeletonIndicator]SurfaceGraphics\[SkeletonIndicator], \ | \[SkeletonIndicator]SurfaceGraphics\[SkeletonIndicator], \ | \[SkeletonIndicator]SurfaceGraphics\[SkeletonIndicator], \ | \[SkeletonIndicator]SurfaceGraphics\[SkeletonIndicator]}] | | (how do I get it to copy/paste what I see in the notebook, instead of | all the internal cell expression stuff?) | | If I change the example to: | | Table[ Plot3D[ BesselJ[0, Sqrt[x^2 + y^2] + t], | {x, -10, 10}, {y, -10, 10}, Axes -> False, | PlotRange -> {-0.5, 1.0} ], | {t, 0, 8} ] // Short | | Then I get 17 graphics rendered. I can click the cell containing them, | then use Cell|Animate Selected Graphics, which then produces the animation. | | I want to have a command that I can execute interactively or associated | with a button, to animate the graphics. I don't want the graphics | displayed when I execute the command that generates the graphics. | | What is the right way to do this? | | Thanks. | | -- | ____________________________________ | Christopher R. Carlen | Principal Laser/Optical Technologist | Sandia National Laboratories CA USA | crcarle at sandia.gov | | | |