您总是可以在画布中创建您的可耕作图像,生成一个 toDataUrl(),然后将该数据 url 作为背景分配给某物,然后让 CSS 进行平铺……只是一个想法。
编辑:如果您在绘制可耕作图像时遇到问题,您可以创建一个 3*widthx3*width 画布,在其上进行常规绘制(假设您从数据的中心正方形抓取数据作为最终结果),然后查看是否您不能从画布的子集绘制到自身。看起来你必须使用:
var myImageData = context.getImageData(left, top, width, height); context.putImageData(myImageData, dx, dy);
(适当的测量)
https://developer.mozilla.org/En/HTML/Canvas/Pixel_manipulation_with_canvas/
编辑二:想法是你有一个足够大的画布,它有一个感兴趣的中心区域,它周围的缓冲区足够大,可以容纳你可能绘制的任何形状,如下所示:
XXX
XCX
XXX
您可以在这个大画布上绘制一次形状,然后X
将该中心区域周围的每个区域盲目地绘制到中心区域(然后清除这些区域以进行下一次绘图)。因此,如果 K 是形状的数量而不是 4*K 绘制,则您有 K + 8 绘制(然后 8 清除)。显然,它的实际适用性取决于形状和重叠问题的数量,尽管我敢打赌它可以被调整。根据形状的复杂性,按照您最初的想法绘制形状 4 次,或者绘制到某个缓冲区或缓冲区,然后将其像素数据绘制 4 次或其他内容可能是有意义的。我承认,这是我脑海中突然出现的一些想法,所以我可能会遗漏一些东西。
Edit III: And really, you could be smart about it. If you know how a set of objects are going to overlap, you should only have to draw from the buffer once. Say you got a bunch of shapes in a row that only draw to the north overlapping region. All you should need to do is draw those shapes, and then draw the north overlapping region to the south side. The hairy regions would be the corners, but I don't think they really get hairy unless the shapes are large.... sigh.. at this point I probably need to quiet down and see if there's any existing implementations of what I speak out there because I'm not sure my writing off-the-cuff is helping anybody.