How can I prevent fast mouse movement from breaking a line in my drawing app?

为君一笑 提交于 2019-11-30 15:03:42

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.

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

Why not use canvas? It has a number of line drawing utilities:

http://www.w3schools.com/html5/html5_ref_canvas.asp

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!