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."

In reply to Re: Event Recognition seems to be too slow by BrowserUk
in thread Event Recognition seems to be too slow by popp0102

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.