As a newcomer to working with canvas and SVG, I am trying to create a line between two specific coordinates. For example, if I have two rectangles, I need to draw a line connecting their centers:
https://i.sstatic.net/Rc6qA.png
Here is what I have tried so far:
Using the following SVG code in HTML:
<svg version="1.1" id="line_2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100%" height="15px" xml:space="preserve">
<path class="path2" fill="#01a09e" stroke-width="5" stroke="#01a09e" d="M0 0 l890 0"/>
</svg>
And applying the following CSS to animate the line drawing:
.path2 {
stroke-dasharray: 1120;
/* stroke-dashoffset: 800; */
animation: draw1 5s linear alternate;
}
@keyframes draw1 {
from {
stroke-dashoffset: 1120;
}
to {
stroke-dashoffset: 2240;
}
}