简体   繁体   English

在画布中绘制自由流动的绘图工具

[英]Drawing free-flow drawing tool in canvas

I researched about Douglas Peucker algorithm. 我研究了Douglas Peucker算法。 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 ). mousemoves事件为您提供了一个时间戳记( 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)); 使用该时间戳计算随时间移动的距离(距离/时间==速度): 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. 强制线到X轴:如果速度低于“慢速”阈值,则仅使用以前的Y坐标,而不是鼠标事件提供的Y。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM