MathGroup Archive 2003

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

Search the Archive

Re: Writing graphics to another notebook?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43079] Re: [mg43061] Writing graphics to another notebook?
  • From: Selwyn Hollis <selwynh at earthlink.net>
  • Date: Mon, 11 Aug 2003 02:15:57 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On Sunday, August 10, 2003, at 01:46  AM, AES/newspost wrote:

> It could save me some unpredictable amount of experimenting with the
> (moderately complicated) Notebook commands if someone could just lay 
> out
> a template structure that would show me what commands to put in a
> primary notebook "A" so as to:
>
> *   Create a new named notebook "B" and open it for writing

B = NoteBookCreate[ <options>]

> *   Within a Do loop or other iterative structure in A, repeatedly
> create graphics (Plots or DisplayTogethers) which are not displayed in 
> A
> but are written to B and displayed there.  (No need to retain any 
> memory
> of the individual graphics in A, if that helps with memory 
> conservation.) *   After exiting the iterative structure, perhaps also 
> Select and
> Animate all the graphics in B (preferably but not necessarily returning
> control to A when this animation is terminated).

See the function popUpAnimate below. This is based on something posted 
here by Omega Consulting some months ago.

> *  Save the notebook B to my HD, maybe each time a new graphic is added
> within the iteration (for safety against crashes or freezes), and also
> at the end of the iteration.

At some point insert NotebookSave[B], or use the option
NotebookAutoSave->True within NotebookCreate.

> *  After exiting the iterative structure and still under program 
> control
> in A, Select and Export the complete string of graphics in B as a
> QuickTime movie.

In principle you should be able to do something like
FrontEndExecute[{FrontEndToken[nb, "SelectionSaveSpecial[QuickTime]"]. 
However, I've not been able to make that work.


------------
popUpAnimate[cmnd_, {t_Symbol, t1_, t2_, dt_}] :=
    Block[{$DisplayFunction = Identity, nb, winsize,
    			aratio, frame1, frame, frames, windowopts},
      frame1 = ReleaseHold[Hold[cmnd] /. t -> t1];
      aratio = AspectRatio /. AbsoluteOptions[frame1];
      winsize = {80, 90} + If[SelectedNotebook[] =!= $Failed,
        {1, aratio}*(ImageSize/.AbsoluteOptions[SelectedNotebook[]]),
        {1, aratio}*(ImageSize/.NotebookCreate[Visible -> False])];
      windowopts = Join[If[$VersionNumber>= 5., {Saveable->False}, {}],
        {WindowElements -> {"StatusArea", "HorizontalScrollBar"},
         WindowSize -> winsize}];
      nb = NotebookCreate[Sequence @@ windowopts];
      NotebookWrite[nb,
      	Cell["Building frames... Please wait.", "Text"],
      	After];
      frames = Table[NotebookWrite[nb,
          frame = graphicCell[Evaluate[cmnd],
          CellMargins->{{20,0},{0,0}}, ImageMargins->{{0,0},{0,0}}];
          NotebookDelete[nb]; frame, All];
          If[$VersionNumber >= 5., Pause[0.1]];
          frame, {t, t1, t2, dt}];
       SelectionMove[nb, All, Notebook];
       SelectionDelete[nb];
       NotebookWrite[nb,
       	Cell["Use the controls at the bottom of the window.", "Text"],
		After];
       NotebookWrite[nb, Cell[CellGroupData[frames, Closed]], All];
       FrontEndExecute[{FrontEndToken[nb, "SelectionAnimate"]}]];
SetAttributes[popUpAnimate, HoldFirst];
graphicCell[graphics_, opts___] :=
Cell[GraphicsData["PostScript", DisplayString[graphics]], "Graphics", 
opts];

(*Example.*)

popUpAnimate[
	Plot[Sin[x], {x, 0, t}, PlotRange -> {{0, 2Pi}, {-1.1, 1.1}}],
{t, Pi/6, 2Pi, Pi/6}]

(*Note that with pre-5.0 Mathematica, the Saveable->False option 
doesn't apply, and Pause[x] doesn't work if x<1. The purpose of 
Pause[0.1] in the code is only to make the drawing of the frames 
proceed more smoothly as they are generated.*)


-----
Selwyn Hollis
http://www.math.armstrong.edu/faculty/hollis


  • Prev by Date: Re: Re: dynamic time warping algorithm
  • Next by Date: discrete frequency distribution
  • Previous by thread: Writing graphics to another notebook?
  • Next by thread: Re: dynamic time warping algorithm