1
$\begingroup$

I made this:

kszamolo[pos_] := Table[{Round[pos[[1]]/d], Round[pos[[2]]/d]}, {d, 1, 4}];

DynamicModule[{lk = {{0, 0}, {0, 0}, {0, 0}, {0, 0}}}, 
  EventHandler[
    Animate[
      Graphics[Disk[lk[[a]], 5], 
        Frame -> True, 
        PlotRange -> {{-50, 50}, {-50, 50}}], 
      {a, 1, 4}, 
      AnimationRunning -> True, 
      AnimationRepetitions -> 1], 
    {"MouseDown" :> (lk = kszamolo[MousePosition["Animate"]])}]]

My goal is to create a window in which I can click in, at which time, the circle should take four steps, one-by-one, on the line between the {0,0} and MousePosition. I think my code has several problems. I'm a beginner, so any help would be nice!

$\endgroup$
1
$\begingroup$
DynamicModule[{pt = {0, 0}},
 ClickPane[
  Graphics[{Orange, Dynamic@Disk[pt]}, PlotRange -> 5, Frame -> True],
  With[{w = MousePosition["Graphics"] - pt}, 
    Do[pt += w/4.; Pause[.1]; FinishDynamic[]; Print[pt], {4}]] &]
]

At the end you can use Eventhandler but for testing ClickPane is quite handy here. Feel free to ask if anything is not clear.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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