MathGroup Archive 2007

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

Search the Archive

Re: DynamicModule, Speed, and locally static variables.

  • To: mathgroup at
  • Subject: [mg82040] Re: [mg82003] DynamicModule, Speed, and locally static variables.
  • From: "W. Craig Carter" <ccarter at>
  • Date: Wed, 10 Oct 2007 04:26:33 -0400 (EDT)
  • References: <>

I think everything I need to know is probably covered in the
two tutorials (IntroductionToDynamic and 

If you were inclined to answer, you might hold off a bit and
let me digest the tutorials... Sorry if I wasted anyone's

On Tue, 9 Oct 2007, W. Craig Carter wrote:

> Subject: [mg82003] DynamicModule, Speed, and locally static variables.
> Dear Mathematica Group,
> Sorry for the long question on combining Module,
> DynamicModule, LocatorPane, Manipulate to produce a
> GraphicsRow.
> I am in the middle of designing small program that uses
> Locator to find the position of a dynamic point and
> Manipulate to control the shape of the locator, and then
> compute an expensive result based on the position (from LocatorPlane)
> and the size (from Manipulate).
> Some calculations are expensive and don't depend on the
> locator position or shape.  Other calculations are
> expensive and do depend on the locator's position and size.
> I am wondering how to scope this.  Do I pay a penalty for
> local variables in DynamicModule that won't change?
> Here is what I am trying, I've made up an artificial
> example below that will (hopefully) show what I am  trying to do.
> It is not working; I am not sure why, but guessing that it
> has to do with variable scope.
> I am hoping for two kinds of help:
> 1) that someone can comment about computational efficiency and
> dynamic variable scope.
> 2) that someone could point to a demo which does something similar.
> 3) I believe that I should be using ControlActive to
> separate the time scales from locator movement and graphics
> production. I can't quite see how that should appear here,
> yet.
> Does it make sense to have the following
> Module[DynamicModule[Manipulate[Locator]]] scoping?
> ----example-----
> demo[f_] :=
>  Module[{StaticExpression=ExpensiveFunction[f],
>          StaticImage3D,StaticContourPlot,
>              PositionInit={1,2}, LocatorSizeInit=1}, (*vars that don't change*)
>         StaticImage3D=Plot3D[StaticExpression];
>         StaticContourPlot=ContourPlot[StaticExpression]
>   GraphicsRow[ (*draw three graphics, 1-fixed, 2-manipulate, 3-result of dynamic variable and manipulate*)
>     Flatten[
>      {
>        StaticImage, (*first-image*)
>          DynamicModule[newdata,{position=PositionInit,LocatorShape=Graphics[g[PositionInit,LocatorSizeInit]]},
>           {Manipulate[ (*manipulate returns a graphics object?*)
>             LocatorShape=Graphics[position,size]; (*dynamic*)
>             newdata=ExpensiveCalculation[position,size,StaticExpression];
>             LocatorPlane[Dynamic[position],StaticContourPlot,Appearance->LocatorShape],(*draw dynamic locator on static image*)
>           {{size,LocatorSizeInit},0,1}],
>         ArrayPlot[ExpensivistCalc[position, size, StaticExpression]] (*the final graphics object and most expensive*)
>           }
>       }
>       ] (*dynamic module*)
>      ] (*flatten*)
>     ] (*graphicsrow*)
>  ] (*module*)
> W. Craig Carter

  • Prev by Date: Re: creating a palette of characters
  • Next by Date: Re: Re: Best way to save data in notebooks
  • Previous by thread: DynamicModule, Speed, and locally static variables.
  • Next by thread: Re: DynamicModule, Speed, and locally static variables.