in reply to Event Recognition seems to be too slow

It is as if the mouse is too fast for the perl program.

If you start up MSPaint (or any other paint program probably), and doodle circles or spirals very quickly, you'll notice that instead of smooth arcs, they are made up of a series of short straight lines.

This is because you can move the mouse far faster than even a compiled C program can keep up with. What the authors of MSPaint do is to remember the last mouse position, and each time they get a new one, the join the old position to the new one with a straight line. At slow speeds, this gives the appearance of smooth arcs as the lines are very short, just 2 or 3 pixels. As the mouse speed increases, so the events are further and further apart, and the straight lines become more and more obvious.

You could do a similar thing within your program. Draw a line from the last position (set when drawing is initiated), to the current position; and then overwrite the last position with the current before leaving the bound sub in preparation for the next.

The are a couple of problems with doing this as your program is currently written.

  1. As you are storing and laballing your 'pixels' as a single 1D array, calculating the line between the two positions becomes unnecessarially complex.

    You could simplify this by storing and labelling your grid using a 2D array/labels.

  2. The second problem is more intractable. Using a whole canvas item object for each pixel in a paint-type app is a rather heavyweight solution Both in memory consumption and processor use.

    The solution is a lot more complex than what you currently have. Basically it involves building up the item line by line in an (normal perl) array and drawing it as a single Line item, adding each new set of coordinates as the mouse moves and deleting the old one.

    In this way, once a line is drawn, it can be selected and manipulated--highlighted; color changed; deleted etc.--as a single item rather than a collection of pixels. But, its quite a lot of work.

Anyway, maybe this will inspire you to move forward with what you are doing.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • Comment on Re: Event Recognition seems to be too slow