Skip to content Skip to sidebar Skip to footer

How Can I Prevent Fast Mouse Movement From Breaking A Line In My Drawing App?

I'm working on a script that allows the user to draw with the mouse: http://jsfiddle.net/ujMGu/ The problem: If you move the mouse really fast it jerks and skips a few places. Is

Solution 1:

Check this out: http://jsfiddle.net/KodeKreachor/9DbP3/6/

The following object on the given link contains the algorithm:

var drawer = new Drawer();

Let me know if you have any questions as to how I did it. The premise is based on Bresenham's line algorithm and should be compatible in older browsers as well.

Solution 2:

You would need to keep track of the previous point and then draw a line between the new point and the previous.

Solution 3:

As @kand has mentioned, a Canvas is really the best tool for drawing.

If you must use your div method, or if this is just for fun, you can extend your approach by saving the previous mouse position and then draw the intervening "pixels" needed to complete the line using, for example, Bresenham's line algorithm.

Post a Comment for "How Can I Prevent Fast Mouse Movement From Breaking A Line In My Drawing App?"