# Manipulate with Locator question

Here is an example from Mathematica's help:

Manipulate[Graphics[Polygon[pt], PlotRange -> 2],
{{pt, {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {1, -1}}}, Locator}]


When I execute this, I can drag any Locator, and the Polygon changes.

Is there a way to access which element of pt is being dragged? So I could have a line in the code that does something different while different points are being dragged? Something like:

Manipulate[doSomethingIfPt2IsBeingDragged;Graphics[Polygon[pt], PlotRange -> 2],
{{pt, {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {1, -1}}}, Locator}]


Generally you access it using the construct pt[[pos]], where "pos" specifies the position of the element in the list of the locator points. In the case at hand it is the list {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {1, -1}}. Its second element, {1,0}, for example is given by pt[], while the first subelement of the second element (i.e. 1) - by pt[[2,1]]. Try the following as an example. It draws a parametric plot changing as soon as you pull the second and/or the fifth locator:

 Manipulate[
Column[{Graphics[Polygon[pt], PlotRange -> 2],
ParametricPlot[{Cos[pt[[2, 1]]*t], Sin[pt[[5, 2]]*t]}, {t, 0,
2 \[Pi]}]
}], {{pt, {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {1, -1}}}, Locator}] Have fun!

This change the color of the polygon (only) while you're dragging it:

Manipulate[
Dynamic[
Graphics[{Extract[{Black, Red, Green, Blue},
Last@Position[col, Except[0.], {1}] + 1], Polygon[pt]},
PlotRange -> 2],
(col = Total /@ (ptsave - pt); ptsave = pt)],
{{pt, {{0, 0}, {1, 0}, {1, 1}}}, Locator},
Initialization :> (ptsave = pt)]

• Thanks. I've been doing something like that. I was just wondering if there was a cleaner (built-in) way to access which point was being dragged. Sep 30, 2014 at 19:16