Typically when adding locators I would use a button i.e. something along the lines
DynamicModule[{pt={{0,0}}},
Column[{LocatorPane[Dynamic[pt],
Dynamic[
Graphics[{Red,Point[pt]},PlotRange->{{-2,2},{-2,2}}]
]
],
Button["Add locator",AppendTo[pt,{0,0}]]}]
]
However, say I wanted to do the same, but within a manipulate and with a SetterBar[]
(or Slider[]
or PopupMenu[]
). I have tried several approaches, but the best I have come up with is at best sketchy. The following code works, but you have to move a locator before a new one shows up (or goes away).
Clear[update]
update[list_, i_] :=If[Length[list] < i, Append[list, {0, 0}], Take[list, i]]<
Manipulate[
DynamicModule[
{pt={{0,0}}},
LocatorPane[Dynamic[pt,(pt=update[#,nrPts])&],
Dynamic[
Graphics[{Red,Point[pt]},PlotRange->{{-2,2},{-2,2}}]
]
]
],
{nrPts,{1,2,3,4},SetterBar}
]
I have tried to place Dynamic[]
in various places, but to no avail. Is there some way to use SetterBar[]
and get as smooth results as with Button[]
?
LocatorAutoCreate->True
to add locators ? $\endgroup$LocatorAutoCreate
option forLocatorPane
that adds/removes points when alt-clicking. $\endgroup$