Re: locator snap
- To: mathgroup at smc.vnet.net
- Subject: [mg88277] Re: locator snap
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Wed, 30 Apr 2008 04:25:53 -0400 (EDT)
- Organization: University of Bergen
- References: <fv6ukg$rmt$1@smc.vnet.net> <4817399A.1030901@gmail.com>
Szabolcs Horvát wrote: > Maarten van der Burgt wrote: >> Dear all, >> >> In the example below the locator can be moved to any position in the >> graphic. >> Can the locator be made to snap to multiples of say 0.1? >> >> Manipulate[Column@{Graphics[{}, Axes -> True], p}, {{p, {0, 0}}, >> Locator}] >> > > Hi Maarten, > > I am not aware of any way to do this directly with Manipulate. (Of > course this does not mean that there doesn't exist a way!) > > Here is an example of doing it directly with Dynamic: > > Graphics[ > Locator[Dynamic[{x, y}, ({x, y} = Round[#, 0.1]) &]], > PlotRange -> 1, Frame -> True, > GridLines -> {#, #} & @ > Table[{x, If[Mod[x, 1/2] == 0, Black, Gray]}, {x, -1, 1, 1/10}] > ] > Sorry, I forgot to mention that x and y must be initialized before this will work: {x, y} = {0, 0} Also, the x in the Table is an unfortunate choice for a local variable name---it has nothing to do with the x in the Dynamic.