Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Automatically colred and indexed custom locators

8 views
Skip to first unread message

Chris Young

unread,
Jan 24, 2012, 5:05:56 AM1/24/12
to
After quite a bit of re-reading the help on LocatorPane, I discovered
the following very helpful hint:

With Appearance->{Subscript[g, 1],Subscript[g, 2],...}, the i\[Null]^th
locator is displayed as Subscript[g, i]. »

Putting this into effect, and putting my graphics in the following
function, I came up with a handy way to index and color auto-created
locators in a Manipulate, so you know at a glance which point is which.
Another nice feature when LocatorPane is used is that you can get very
smooth snapping to a grid just by including that in the range
specification. Below, it's the third list in {{-2, -2}, {2, 2}, {.25,
..25}}.

Only two small problems:

1) When first created, the points don't get snapped to the grid.

2) If the locators are made too small, offsetting the text labels
nudges them away from the correct positions.

http://home.comcast.net/~cy56/Mma/CustomLocators.nb
http://home.comcast.net/~cy56/Mma/CustomLocatorsPic1.png
http://home.comcast.net/~cy56/Mma/CustomLocatorsPic2.png

Chris Young
cy...@comcast.net

locGraphics[k_, n_, locSize_, opac_, offset_] :=
Graphics[
{Opacity[opac], Hue[0.85 (k - 1)/(n - 1)], Disk[{0, 0}],
Opacity[1], Black,
Circle[{0, 0}],
Line[{{-1.5, 0}, {1.5, 0}}],
Line[{{0, -1.5}, {0, 1.5}}],
Text[k, {0, 0}, offset]},
ImageSize -> locSize
]

Manipulate[
DynamicModule[
{P, n},

P = {{0, 0}, {1, 1}};

Dynamic @
LocatorPane[
Dynamic @ P,

Dynamic @
Show[
Graphics[{Thick, Line[P]}],
Axes -> True,
PlotRange -> 2,
GridLines -> {Range[-2, 2, 0.25], Range[-2, 2, 0.25]},
GridLinesStyle -> LightGray
],
{{-2, -2}, {2, 2}, {.25, .25}},

LocatorAutoCreate -> True,
Appearance -> (
n = Length[P];
Table[locGraphics[k, n, locSize, opac, offset], {k, 1, n}]
)
]
],
{{locSize, 15}, 5, 80, 1},
{{opac, 0.75}, 0, 1},
{{offset, {0, 0}}, {-2, -2}, {2, 2}, {0.25, 0.25}}
]


Christopher Young

unread,
Jan 25, 2012, 7:12:56 AM1/25/12
to
Thanks, that fixed the problem with the snapping not working when the
point is created. The only problem is, the points can now only be
dragged one grid unit at a time.

I'm working on something that will work completely, but it looks like I
may have to give up using Manipulate. I really don't want to have to
click and drag only 1 unit at a time.


On Jan 24, 2012, at 7:54 AM, Heike Gramberg wrote:

> Looks nice. To make the locators snap to the grid on creation you can
do something like this:
>
> locGraphics[k_, n_, locSize_, opac_, offset_] :=
> Graphics[{Opacity[opac], Hue[0.85 (k - 1)/(n - 1)], Disk[{0, 0}],
> Opacity[1], Black, Circle[{0, 0}], Line[{{-1.5, 0}, {1.5, 0}}],
> Line[{{0, -1.5}, {0, 1.5}}], Text[k, {0, 0}, offset]},
> ImageSize -> locSize]
>
> Manipulate[
> DynamicModule[{n},
> P = Round[P, .25];
> LocatorPane[Dynamic[P],
> Show[Graphics[{Thick, Line[P]}], Axes -> True, PlotRange -> 2,
> GridLines -> {Range[-2, 2, 0.25], Range[-2, 2, 0.25]},
> GridLinesStyle -> LightGray], {{-2, -2}, {2, 2}, {.25, .25}},
> LocatorAutoCreate -> True, Appearance -> (n = Length[P];
> Table[locGraphics[k, n, locSize, opac, offset], {k, 1, n}])]],
> {{P, {{0, 0}, {1, 1}}}, None},
> {{locSize, 15}, 5, 80, 1}, {{opac, 0.75}, 0,
> 1}, {{offset, {0, 0}}, {-2, -2}, {2, 2}, {0.25, 0.25}}]
>
> Basically, all I've done her is changing P from being a local variable
of the DynamicModule to a
> controller of the enclosing Manipulate and adding the line P =
Round[P, .25];
>
> Heike
>
> By the way, changing P to a controller should also solve the problem
in your other
> post about morphing Bezier curves.

Heike Gramberg

unread,
Jan 25, 2012, 7:14:58 AM1/25/12
to
On 24 Jan 2012, at 11:05, Chris Young wrote:

> After quite a bit of re-reading the help on LocatorPane, I discovered

> the following very helpful hint:
>
> With Appearance->{Subscript[g, 1],Subscript[g, 2],...}, the
i\[Null]^th
> locator is displayed as Subscript[g, i]. =BB
>
> Putting this into effect, and putting my graphics in the following
> function, I came up with a handy way to index and color auto-created

> locators in a Manipulate, so you know at a glance which point is
which.
> Another nice feature when LocatorPane is used is that you can get very

> smooth snapping to a grid just by including that in the range
> specification. Below, it's the third list in {{-2, -2}, {2, 2}, {.25,

> ..25}}.
>
> Only two small problems:
>
> 1) When first created, the points don't get snapped to the grid.
>
> 2) If the locators are made too small, offsetting the text labels
> nudges them away from the correct positions.
>
> http://home.comcast.net/~cy56/Mma/CustomLocators.nb
> http://home.comcast.net/~cy56/Mma/CustomLocatorsPic1.png
> http://home.comcast.net/~cy56/Mma/CustomLocatorsPic2.png
>
> Chris Young
> cy...@comcast.net
>
> locGraphics[k_, n_, locSize_, opac_, offset_] :=
> Graphics[
> {Opacity[opac], Hue[0.85 (k - 1)/(n - 1)], Disk[{0, 0}],
> Opacity[1], Black,
> Circle[{0, 0}],
> Line[{{-1.5, 0}, {1.5, 0}}],
> Line[{{0, -1.5}, {0, 1.5}}],
> Text[k, {0, 0}, offset]},
> ImageSize -> locSize
> ]
>
> Manipulate[
> DynamicModule[
> {P, n},
>
> P = {{0, 0}, {1, 1}};
>
> Dynamic @
> LocatorPane[
> Dynamic @ P,
>
> Dynamic @
> Show[
> Graphics[{Thick, Line[P]}],
> Axes -> True,
> PlotRange -> 2,
> GridLines -> {Range[-2, 2, 0.25], Range[-2, 2, 0.25]},
> GridLinesStyle -> LightGray
> ],
> {{-2, -2}, {2, 2}, {.25, .25}},
>
> LocatorAutoCreate -> True,
> Appearance -> (
> n = Length[P];
> Table[locGraphics[k, n, locSize, opac, offset], {k, 1, n}]
> )
> ]
> ],

Christopher Young

unread,
Jan 26, 2012, 3:25:23 AM1/26/12
to
That looks great! It does everything right. Thanks very much.

On Jan 25, 2012, at 9:24 AM, Heike Gramberg wrote:

>>> locGraphics[k_, n_, locSize_, opac_, offset_] :=
>>> Graphics[{Opacity[opac], Hue[0.85 (k - 1)/(n - 1)], Disk[{0, 0}],
>>> Opacity[1], Black, Circle[{0, 0}], Line[{{-1.5, 0}, {1.5, 0}}],
>>> Line[{{0, -1.5}, {0, 1.5}}], Text[k, {0, 0}, offset]},
>>> ImageSize -> locSize]

Chris Young
cy...@comcast.net
0 new messages