Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

RE: Real Time Animation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36890] RE: [mg36796] Real Time Animation
  • From: Goyder Dr HGD <H.Goyder at rmcs.cranfield.ac.uk>
  • Date: Tue, 1 Oct 2002 04:45:14 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Many thanks to all who replied.

The original problem was as follows:

In a presentation I wish to use Plot to generate a sequence of frames and
then animate them. The problem is that the audience sees the animation
twice. Once when the frames are being generated and then again after I have
closed the group and double clicked on the top graphic. However, the first
showing during generation is enough (but uncontrolled). 

Is it possible to tidy up the generation of the graphic so that it becomes
the animation?


There were two main solutions which I now apply to my real problem and not
the simple, generic, problem in the original post. 
The real problem was how to build up a probably density function (PDF) in
real time. In the examples below I redraw the PDF every time I add 10
points.

Initialise

<<Statistics`ContinuousDistributions`;
<<Statistics`DataManipulation`;
<<Graphics`Graphics`;
<< JLink`;
wb=WeibullDistribution[2.101349094155377,22.58126779173235`];
midpts=Table[i,{i,0.5,50,1}];

Solution from Omega Consulting

GraphicCell[graphics_] :=
   Cell[GraphicsData["PostScript", DisplayString[graphics]],"Graphics"]

Block[{$DisplayFunction=Identity, graphs},
  data={};
   graphs =
         Table[data=Flatten[Join[data,RandomArray[wb,10]]];
      freq=BinCounts[data,{0,50,1}];
      GraphicCell[
        BarChart[Transpose[{freq,midpts}],ImageSize ->500] ], {500}];
     NotebookWrite[EvaluationNotebook[],Cell[CellGroupData[graphs,Closed]]];
     SelectionMove[EvaluationNotebook[], All, GeneratedCell];
     FrontEndExecute[{FrontEndToken[EvaluationNotebook[], 
        "SelectionAnimate"]}]
     ]

This solution works but it generates 500 frames and sometimes exceeds the
memory. 
The paradigm here is generate all frames, then animate all frames.  We
really need a loop that does:

 generate next frame, delete last frame, show next frame

Is it possible to do this?

Bobby Treat also offered a solution involving SelectionMove.


The second solution was from Jerry Blimbaum and uses JAVA

InstallJava[];
UseFrontEndForRendering = False;
createWindow[] := Module[{frame},
    frame = 
      JavaNew["com.wolfram.jlink.MathFrame", "Probability Density
Function"];
    drawArea = JavaNew["com.wolfram.jlink.MathCanvas"];
    drawArea@setUsesFE[UseFrontEndForRendering];
    drawArea@setSize[800, 600];
JavaBlock[frame@setLayout[JavaNew["java.awt.BorderLayout"]];
      frame@add[drawArea, ReturnAsJavaObject[BorderLayout`CENTER]];
      frame@pack[];
      frame@setSize[800, 600];
      frame@setLocation[100, 100];
      JavaShow[frame]];
frame
]
ClearAll[drawString];
  drawString[] :=(
    data=Flatten[Join[data,RandomArray[wb,10]]];
    freq=BinCounts[data,{0,50,1}];
    BarChart[Transpose[{freq,midpts}],ImageSize ->500, 
      DisplayFunction -> Identity])
  LoadJavaClass["java.lang.Thread"];
 AnimationPlot[n_] := JavaBlock[
    Block[{frm}, frm = createWindow[];
      Do[(obj = drawString[]; 
          drawArea@setMathCommand["obj"];
           drawArea@repaintNow[];
          Thread@sleep[];) ,{n} ]]]
data={};
 AnimationPlot[500];

This solution works and does not use significant memory. However, we have
not managed to control the speed of this animation. The JAVA code sleep does
not work nor does the use of a Mathematica Pause which always rounds up to
an integer (is this a bug?).

Hugh Goyder


  • Prev by Date: A Bessel Integral Re:
  • Next by Date: Animations -- delete after viewing
  • Previous by thread: A Bessel Integral Re:
  • Next by thread: Re: RE: Real Time Animation