MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: forming continuous "trail" with Locator


Murray Eisenberg wrote:
> Is there some way in Mathematica 6 to use a Locator so as to create a 
> continuous-appearing "trail" after you click and then drag the cursor 
> around?
> 
> Of course one could write code allowing addition of points through 
> successive clicks, and then one could try to click repeatedly on 
> successive points very near one another, but that could get very tedious.
> 
> I mean the sort of thing one gets in drawing programs (and with the 
> Mathematica 6 2D Drawing Tools).

I don't know whether and how you could do this with a Locator, but since 
I have experimented with EventHandler in the last view days I came up 
with this:

DynamicModule[{line = {}}, EventHandler[
   Graphics[{
     Dynamic[
       Switch[Length[line],
         0, {},
         1, Point[line[[1]]],
         _, Line[line]
     ]]
     }, Frame -> True, PlotRange -> {{-1, 1}, {-1, 1}}],
   {
    "MouseDown" :> (line = {MousePosition["Graphics"]}),
    "MouseDragged" :> (AppendTo[line, MousePosition["Graphics"]]),
    "MouseUp" :> (AppendTo[line, MousePosition["Graphics"]])
    }]
  ]

it's pretty simple and not very appealing but probably a good starting 
point...

hth,

albert


  • Prev by Date: How show Locator point and its image under a function?
  • Next by Date: Interpolation incorrectly depends on order of data points
  • Previous by thread: Re: forming continuous "trail" with Locator
  • Next by thread: Re: forming continuous "trail" with Locator