如何在 html5 canvas 2d 上下文中实现 sineWaveTo squareWaveTo 和 sawWaveTo 线?
我想尝试实现这些,以便可以以类似于 lineTo() 的方式使用它们。从当前点开始,给定结束坐标,函数将绘制一条方形线、锯齿线或正弦线,一直到结束坐标。
我不知道我们是否可以同时考虑幅度和频率,因为我猜这会导致线条实际在终点结束时出现问题,但应该根据距离和幅度计算频率。
幅度和频率作为参数 <假设我们调整与距离成比例的频率,应该是可能的。
到目前为止,我发现的只是 ActionScript 中的示例,而且我似乎无法像我想要的那样将它们专门适合非动画线条绘制函数。
非常感谢任何帮助,到目前为止,我已经想出了各种各样的时髦螺旋,但没有接近目标。我不太热衷于数学,所以欢迎使用伪代码;)
哈哈哈,“风滚草徽章”……我认为已经溢出了心理堆栈。
I would like to try an implement these so that they can be used in a manner similar to lineTo(). Starting from the current point, given the ending coordinates the functions would draw either a square, saw, or sine line all the way to the the ending coordinates.
I dont know if we can factor in both Amplitude AND Frequency because I guess it would cause problems with the line actually finishing on the ending point but calculating frequency from distance and amplitude should.
Amplitude and Frequency as parameters should be possible, assuming we adjust the frequency proportional to the distance.
So far, all i've found is examples in ActionScript and I cant seem to purpose-fit them to a non-animated line drawing function like I want to.
Any help is greatly appreciated, so far I've come up with whole sorts of funky spirals but nothing close to the goal. I'm not much of a math buff so pseudo code welcome ;)
Hahahah, "tumbleweed badge"... methinks overflowed the mental stacks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一下这个方法。只执行 sin(),但是,我相信您能够弄清楚其余的事情。 (仅在 Firefox 中测试,顺便说一句。)
看起来像:
Try this for good measure. Does only sin(), but, I'm sure you'll be able to figure out the rest. (Tested only in Firefox, BTW.)
Looks like: