Is there any way to accelerate the mousemove event?

前端 未结 2 964
一生所求
一生所求 2020-11-28 10:29

I wrote a little drawing script (canvas) for this website: http://scri.ch/

When you click on the document, every mousemove event basically executes the

相关标签:
2条回答
  • 2020-11-28 10:31

    Cool site, unfortunately there is no way to request the current position of the mouse with JavaScript, the only hooks you have are the events you're already using. If you must have more control I'd look at using flash where you can change the frame rate and request the mouse position.

    trace("Mouse X: " + _xmouse);
    trace("Mouse Y: " + _ymouse);
    
    0 讨论(0)
  • 2020-11-28 10:40

    If you want to increase the reporting frequency, I'm afraid you're out of luck. Mice only report their position to the operating system n times per second, and I think n is usually less than 100. (If anyone can confirm this with actual specs, feel free to add them!)

    So in order to get a smooth line, you'll have to come up with some sort of interpolation scheme. There's a whole lot of literature on the topic; I recommend monotone cubic interpolation because it's local, simple to implement, and very stable (no overshoot).

    Then, once you've computed the spline, you can approximate it with line segments short enough so that it looks smooth, or you can go all-out and write your own Bresenham algorithm to draw it.

    If all this is worth it for a simple drawing application... that's for you to decide, of course.

    0 讨论(0)
提交回复
热议问题