简体   繁体   English

用于绘制具有厚度/宽度的线的算法

[英]Algorithm for drawing line with thickness / width

I'm looking for a fast algorithm that draws lines with a certain thickness. 我正在寻找一种快速算法来绘制具有一定厚度的线条。 The lines don't have to be antialiased, speed is priority. 线路不必抗锯齿,速度优先。 Something fairly simple like this would suffice: 像这样简单的东西就足够了:

The use case is a Javascript game where worms leave trails. 用例是一个Javascript游戏,其中蠕虫留下痕迹。 (HTML5 Canvas obviously draws lines, but getImageData() is very slow and so is collision detection) (HTML5 Canvas显然会绘制线条,但getImageData()非常慢,因此碰撞检测也是如此)

I couldn't find anything that does this for the last 2.5 hours. 在过去的2.5小时里,我找不到任何可以做到这一点的事情。 And yes, I'm aware that there are almost identical questions on SO, quite a lot of them in fact, but not a single one has a working solution. 是的,我知道在SO上几乎有相同的问题,实际上有很多问题,但没有一个问题有一个可行的解决方案。 The only solution I currently have is to draw circles along a Bresenham line, which is not very efficient. 我目前唯一的解决方案是在Bresenham线上绘制圆圈,这不是很有效。

Some code (pseudo-code, JS or at least a link to an article) would be great. 一些代码(伪代码,JS或至少是文章的链接)会很棒。

http://members.chello.at/~easyfilter/bresenham.html http://members.chello.at/~easyfilter/bresenham.html

check at the bottom. 检查底部。 It is an anti-aliased line, but should be easy enough to mod to non-anti-aliasing. 它是一个消除锯齿的线,但应该很容易修改为非抗锯齿。

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

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