MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: RE: Re: How to animate?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg38552] Re: [mg38540] RE: [mg38529] Re: How to animate?
  • From: Omega Consulting <info at omegaconsultinggroup.com>
  • Date: Wed, 25 Dec 2002 03:13:04 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

At 05:40 AM 12/24/2002, David Park wrote:
>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.

This is not necessary. You can create the entire closed cell group in the 
kernel.

GraphicsCell[gr_] :=
    Cell[GraphicsData["PostScript", DisplayString[gr]],"Graphics"]

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} ];

NotebookWrite[EvaluationNotebook[],
   Cell[CellGroupData[
     Map[GraphicsCell, frames1],
   Closed]]
];
SelectionMove[EvaluationNotebook[], All, GeneratedCell];
FrontEndExecute[{FrontEnd`SelectionAnimate[200, AnimationDisplayTime ->
0.1,AnimationDirection -> Forward]}]

>However, I find it very difficult to
>NotebookRead the cells from the side notebook.

This is because SelectionEvaluate does not do what you (and almost everyone 
else) expect it to do. It does not cause an evaluation within your 
evaluation. What it does is basically the same as Shift-Enter. Two things 
are causing you trouble.

1) It changes the selection in the notebook. (Just like Shift-Enter does.) 
If you want to select the graphics cells, you need to do it with 
SelectionMove or NotebookFind.
2) The evaluation is queued for evaluation by the fe, but it doesn't 
evaluate until after all current evaluations. This means that you can't use 
the results of a SelectionEvaluate in the same command as the 
SelectionEvaluate.

There are ways to get around this limitation, but they're pretty 
cumbersome. You must have the SelectionEvaluated commands do the reading 
and writing, not your original set of commands. This will do what you want:

In[]:=
cmds = Map[
       Cell[#, "Input"]&, {"Plot[Sin[x],{x,0,2 Pi}];",
         "NotebookFind[EvaluationNotebook[], \"Graphics\", All, CellStyle];",
         "graphics=NotebookRead[EvaluationNotebook[]];",
         "NotebookWrite["<>ToString[EvaluationNotebook[],InputForm]<>
           ", graphics];", "NotebookClose[EvaluationNotebook[]];"}];

In[]:=
nb = NotebookPut[Notebook[cmds, Visible->False]];
SelectionMove[nb, All, Notebook];
SelectionEvaluate[nb]

To see what's going on, remove the Visible option and insert some Pause 
commands to slow things down.

>David Park
>djmp at earthlink.net
>http://home.earthlink.net/~djmp/

--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"
http://omegaconsultinggroup.com



  • Prev by Date: FrontEnd-Kernel Synching, was: How to animate?
  • Next by Date: Re: Appending to a matrix?
  • Previous by thread: RE: Re: How to animate?
  • Next by thread: Display vs Export