Message Boards Message Boards

0
|
4073 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Unexplained ClickPane Behaviour

Posted 9 years ago

Sometimes ClickPane does not seem to work. Here we see the correct operation - mouse clicks create points on the output row:

AnImg[p_] := Framed@Graphics[Point[p]];
DynamicModule[
 {pts = {}},(* some points to plot - starts empty *)
 ClickPane[
  AnImg[Dynamic[pts]], (* Plot the points in a Frame *)
  AppendTo[pts, #] & (* add clicks to the list of points *)
  ]
 ]

(A rather neat Mathematica snippet) So far so good, but what if I alter AnImg[] to overlay the points on an image? First altering AnImg[]:

AnImg[p_] := ImageCompose[ (* two images combined into one output image*)
   Graphics[{Blue , Opacity[0.5], Rectangle[]}],
   Graphics[{PointSize[0.05], Red, Opacity[0.5], Point[p]}]
   ];
AnImg[{{-20, -20}, {0, 0}, {20, 20}}] (* Just to show that the altered function works *)

But ... our original ClickPane no long seems to work ...

DynamicModule[
 {pts = {{-20, -20}, {0, 0}, {20, 20}}}, (* some points to plot - starts empty *)
 ClickPane[
  AnImg[Dynamic[pts]], (* Plot the points in a Frame *)
  AppendTo[pts, #] &
  ]
 ]

It displays the first calculation of the AnImg[] but mouse-clicks are no longer detected.

I have attached my file and would welcome any comments; I must have missed something.

Attachments:
POSTED BY: Andrew Macafee
3 Replies
Posted 9 years ago

Thank you for answering this - I see what you mean.

This is really helpful.

(Do you know where I can read about debugging dynamics? I can't see what I need in Tuning & Debugging. I am familiar with the debugger for normal programmes so my watchpoint on pts does not get triggered (for instance))

I have given feedback on http://reference.wolfram.com/language/ref/ClickPane.html and suggested that the description/specification for ClickPane or the implementation may have an error.

I have included a new example notebook illustrating your observations and adding the clarifications.

Attachments:
POSTED BY: Andrew Macafee
POSTED BY: Sean Clarke

There's a difference between an Image and a Graphics in Mathematica. Images are rasterized things like bitmaps. Graphics are actual descriptions of images which are easy to manipulate (they're kinda like SVG images).

When using ClickPane, you should use Graphics, not Images. ImageCompose produces an Image. Use Show to combine graphics. ImageCompose takes Graphics and turns them into Images. You would want your code to look something like this:

AnImg[p_] := 
 Show[(*two images combined into one output image*)
  Graphics[{Blue, Opacity[0.5], Rectangle[{-20, -20}, {20, 20}]}], 
  Graphics[{PointSize[0.05], Red, Opacity[0.5], Point[p]}]]

DynamicModule[{pts = {{-20, -20}, {0, 0}, {20, 20}}}, 
 ClickPane[AnImg[Dynamic[pts]], AppendTo[pts, #] &]]
POSTED BY: Sean Clarke
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