I researched about Douglas Peucker algorithm. Maybe I can use it as an alternative solution to just free flow my drawing. But my problem is that when I'm drawing, the previous drawn points are also moving. Is there any way to make the drawn lines stationary while drawing within the same collection of points in an array.
Here is the code
The mousemoves event gives you a timestamp (event.timeStamp
).
Use that timestamp to calculate the distance moved over time (distance/time==speed): var distance=Math.sqrt((prevX-thisX)*(prevX-thisX)+(prevY-thisY)*(prevY-thisY));
To force the line to an X-axis: If the speed is below your "slow" threshold, just use the previous Y-coordinate instead of the Y supplied by the mouse event.