I am trying to curve image along the path.
I did this by cutting image into parts, placing them on a certain point on the line, and rotating them by tangent angle of that point.
Everything is great, except if you look closely there are cracks between each image section, although each image begins exactly where previous ends.
Can anybody help to get rid of those cracks.
Here is jsBin.
Bezier 2nd & 3rd order ScanLine rendering
Drawing an image with opacity in sections will not work as there will always be some pixels overlapping. The result will be seams.
Quality and quick, webGL
The easiest approch is to use WebGL and render the curve as a set of polygons. It is quick, and can be rendered offscreen.
Scanline rendering
First I must point out this is very SLOW and not for animation.
The alternative is to create a scan line render that scans the pixels one row at a time. For each pixel you find the closest point on the curve as the bezier position 0-1 and the distance from the curve. This gives you the x and y mapping coordinate of the image. You also need to find which side of the curve you are. This can be found by computing the tangent at the point on the curve and using the cross product of the tangent and pixel to find which side of the line you are.
This method will work for most curves but breaks down when the curve is self intersecting or the width of the source image causes pixels to overlap. As scan line rendering ensures no pixels will be written twice the only artifacts generated will be seams along lines where the distance to the curve abruptly changes.
The advantage of scan line rendering is that you can create very high quality rendering (trading off time) using super sampling.
Workers
Scanline rendering is ideal for parallel processing techniques. Using workers to do parts of the scan will give a nearly linear performance boost. On some browsers you can find the number of available processing cores with
window.clientInformation.hardwareConcurrency
creating any more workers than this value will not give you improvement but will start to reduce performance. If you can not find the number of cores it is best to keep an eye on performance and not spawn any more workers if throughput is not increasing.Demo
The following is the most basic scan line render of a curve without any super sampling. The function at the heart of the method
getPosNearBezier
finds the position via brute force. It samples all the points along the curve to find the closest. As is this method is VERY slow, but there is plenty of room for optimisation and you should be able to double or triple the performance with some extra smarts.WebGL example
This example just renders the bezier onto an offscreen canvas using webGL and then renders that canvas onto the 2D canvas, so you still have full use of the 2D API.
Its a bit of a mess. But from your bin you know what you are doing so hopefully this will help.