I am creating a game in SVG and require square tiles to be placed along a path, named a road.
The path can be curved or placed in an angle and I would like to rotate the square tiles relative to the path.
My current structure looks like this:
<defs>
<rect id="tile" width="200" height="200" stroke-width="5" stroke="red"/>
</defs>
<g style="stroke-width=10px; stroke:#23238E;>
<path id="road1" d="M100 100 L 500 100"/>
<path id="road2" d="M500 100 L 200 100"/>
</g>
My current understanding of SVG tells me I will have to calculate the positions of the tiles through interpolation but can I rotate the tiles relative to the path in an automated fashion?
So how can I apply <use x="xx" y="yy" orient="auto" xlink:href="tile"/> ?
The roads are generated from the following information:
id = #
vector2D = {
x1 = #
y1 = #
x2 = #
y2 = #
}
tiles = # // number of tiles in road
Raphael http://raphaeljs.com provides the angle of a path at any point through
path.getPointAtLenght(x). SVG has a native implementation, but it doesn’t provide the angle. You could look into Raphael’s source to see what’s going on. Here is the relevant bit:Where point.alpha is the rotation angle.