Message Boards Message Boards

Constrained Locator in Wolfram Player?

Posted 4 months ago

I'm not sure if this is properly a question about Wolfram Player or is just my use of the Wolfram Language causing problems.

I've created a dynamic graphic with a constrained locator just fine in Mathematica. However, it fails when opened/previewed in Player. See attached notebook - the top, unconstrained example works just fine in Player but the second, constrained example does not. Is there a workaround of some sort here?

I realize that in this particular example I could simply use Manipulate, but a general Player-compatible approach would be valuable to me.

Thanks.

Attachments:
POSTED BY: Todd Pytel
2 Replies
Posted 4 months ago

It works in Player if the constraints definition is made to be within the DynamicModule:

DynamicModule[
  {pt={0.5,0},constrain},
  constrain[{x_,y_}]:={Piecewise[{{0,x<0},{x,0<=x<=1},{1,x>1}}],0};
  Graphics[
    {
    {Thick,Circle[]},
    Line[{{0,0},Dynamic[pt]}],
    Locator[Dynamic[pt,(pt=constrain[#])&]]
    },
    PlotRange->1.1
  ]
]
POSTED BY: Hans Milton
Posted 4 months ago

Oh, beautiful! Of course that makes sense... I even suspected that we were just lacking the definition but didn't think to add it to DynamicModule's initialization list. Duh.

Thank you so much!

POSTED BY: Todd Pytel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract