Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How can I change the color of a Locator in a Manipulate? As an example, consider the following.

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

It's easy enough to hide the Locator and then add any primitives that I want:

Manipulate[
  Graphics[{
    Line[{{0,0},pt}],
    {PointSize[Large],Red,Point[pt]}},
    PlotRange -> 2
  ], {{pt,{0,0}},{-2,-2},{2,2}, Locator, Appearance -> None}]

The Locator itself, though, seems impervious to any directives I try.

share|improve this question
add comment

3 Answers

up vote 11 down vote accepted

As far as I know, you can't change the colour of the default locator directly, but you could use the specification for the default locator to create a coloured version of the default locator. These specifications can be found in the file MiscExpressions.tr located in $InstallationDirectory\SystemFiles/FrontEnd/TextResources. It turns out that the locator is specified as

GraphicsBox[
 InsetBox[GraphicsBox[{col, {AbsoluteThickness[1], 
     Antialiasing -> False, 
     LineBox[{{{0, -10}, {0, -2}}, {{0, 2}, {0, 10}}, {{-10, 0}, {-2, 
         0}}, {{2, 0}, {10, 0}}}], Antialiasing -> True, 
     CircleBox[{-0.5, 0.5}, 5]}, {AbsoluteThickness[3], Opacity[0.3], 
     CircleBox[{-0.5, 0.5}, 3]}}, ImageSize -> 17, 
   PlotRange -> {{-8, 8}, {-8, 8}}], {0, 0}, Center]]

So using this you could create a coloured locator by doing something like

loc[col_] := Rasterize[
  ToExpression@
   GraphicsBox[{col, {AbsoluteThickness[1], Antialiasing -> False, 
      LineBox[{{{0, -10}, {0, -2}}, {{0, 2}, {0, 10}}, {{-10, 0}, {-2,
           0}}, {{2, 0}, {10, 0}}}], Antialiasing -> True, 
      CircleBox[{-0.5, 0.5}, 5]}, {AbsoluteThickness[3], Opacity[0.3],
       CircleBox[{-0.5, 0.5}, 3]}}, ImageSize -> 17, 
    PlotRange -> {{-8, 8}, {-8, 8}}],
  Background -> None]

Graphics[{Disk[], Locator[{0, 0}, loc[Darker[Green]]]}]

Mathematica graphics

share|improve this answer
    
+1 You could also Rasterize a default locator, just in case WR decides to change the def. Then modifying the coloring seems easy –  belisarius Mar 21 '12 at 16:56
    
Yes, this is as I thought. Thanks! –  Mark McClure Mar 21 '12 at 18:31
    
+1 for throwing in MiscExpressions.tr! –  István Zachar Oct 28 '12 at 16:55
add comment

You could simply draw the locator with crosshairs. Color of circle, crosshairs and inner disk can be set as desired.

Manipulate[
    Graphics[{Line[{{0, 0}, pt}]}, PlotRange -> 2], 
    {{pt, {0, 0}}, {-2, -2}, {2, 2}, Locator, 
       Appearance -> Graphics[{Black,
           Line[{{0, 1.5}, {0, 3}}],Line[{{0, -1.5}, {0, -3}}],
           Line[{{-1.5, 0}, {-3, 0}}], Line[{{1.5, 0}, {3, 0}}],
           Circle[{0, 0}, 2], Blue, Disk[]}, ImageSize -> 20]}]

locator


If you don't require a replica of the default locator and a single color suffices, you might use \[CircleDot] or \[CirclePlus]. For example,

Manipulate[Graphics[{Line[{{0, 0}, pt}]}, PlotRange -> 2], 
  {{pt, {0, 0}}, {-2, -2}, {2, 2}, Locator,  
    Appearance -> Style["\[CircleDot]", Blue, 24]}]

characterlocator

share|improve this answer
add comment

Use Appearance->SomeGraphicsObject:

l = Graphics[{Red, Disk[{0, 0}, .1]}, ImageSize -> 10];    
Manipulate[Graphics[{Line[{{0,0},pt}]},PlotRange->2],
 {{pt,{0,0}},{-2,-2},{2,2},Locator,Appearance->l}]

Mathematica graphics

You can use any Graphics or Graphics3D object for this, i.e.:

l = Graphics[{Red, Table[Circle[{0, 0}, i], {i, 3}]}, ImageSize -> 20];

Mathematica graphics

or

l=Graphics3D[{Blue,Cylinder[],Red,Sphere[{0,0,2}],Black,Thick,Dashed,
 Line[{{-2,0,2},{2,0,2},{0,0,4},{-2,0,2}}],Yellow,
 Polygon[{{-3,-3,-2},{-3,3,-2},{3,3,-2},{3,-3,-2}}],Green,
 Opacity[.3],Cuboid[{-2,-2,-2},{2,2,-1}]},ImageSize->50];

Mathematica graphics

share|improve this answer
    
What if the Locator is not in a Manipulate? Take e.g. Graphics[Dynamic@Locator[], PlotRange -> 1] How the appearance be changed here? Appearance -> Graphics@Disk[] does not work as an option to the Locator. –  Szabolcs Mar 21 '12 at 16:43
    
@Szabolcs You can always just do Graphics[Locator[{0, 0}, l], PlotRange -> 1] –  Eli Lansey Mar 21 '12 at 16:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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