I call this Manipulate from a package:

GraficoSeno[]:= {Manipulate[pntx=First[pt]; pnty=Last[pt];
        Graphics[{{Red, Circle[]},
        {Thick, Line[{{0, 0}, pt}]},
        {Thick, Line[{{0,0},{0,pnty}},VertexColors->{Blue, Blue}]}, 
        {Thick, Line[{{pntx,0}, pt},VertexColors->{Blue, Blue}]}},
        Axes -> True, PlotRange -> 3/2],
        {{pt, {1, 1}/Sqrt[2]}, Locator, TrackingFunction ->((pt = Normalize[#]) &)},ContentSize->{300,300}]

Suddenly this strange thing happens:


Why is that blinking happening?

  • $\begingroup$ That happened because of i used, as Kuba suggest, pntx as a shared variable. $\endgroup$
    – Ale1794
    May 18, 2017 at 9:27

1 Answer 1


pnty, pntx are not scoped. If many instances of your gui share them, change in any will trigger each other resulting in a loop.

You can scope it as follows:

DynamicModule[{pnty, pntx}, Manipulate[...

But this makes the performance of Locators really bad. I don't know why but it should not happen.

Manipulate is a big black box, I don't think there is a point in spending time investigating that issue. For more complicate case you can rewrite everything as DynamicModule and for less, like here, we can scope pnty in Manipulate itself with {pnty, None} variable spec, see more in:

What does None mean in a control specification for Manipulate?

GraficoSeno[] := {Manipulate[    
     { {Red, Circle[]}
     , {Thick, Dynamic @ Line[{{0, 0}, pt}]}
     , {Dynamic @ Point[{{0, 0}, {0, pnty}}]}
     , {Dynamic @ Point[{{0, 0}, {pntx, 0}}]}
     , {Thick, Blue, Dynamic @ Line[{{0, 0}, {0, pnty}}]}
     , {Thick, Blue, Dynamic@Line[{{pntx, 0}, pt}]}
     , Axes -> True
     , PlotRange -> 3/2
  , {{pt, {1, 1}/Sqrt[2]}, Locator, TrackingFunction -> ((pt = Normalize[#]; {pntx, pnty} = pt) &)}
  , {pntx, None}
  , {pnty, None}
  , ContentSize -> {300, 300}

p.s. I've moved pntx to the TrackingFunction, as well as I've added Dynamic inside Graphics, this way the whole Graphics does not have to be recreated when you move controllers. See e.g.:



Not the answer you're looking for? Browse other questions tagged or ask your own question.