Reputation: 10583
So I can draw a line in Fabric JS;
var line = new fabric.Line([x1, y1, x2, y2], {
stroke: 'red',
strokeWidth: 0.9
});
canvas.add(line);
However I only want to draw perhaps half of the line or 20% of the line, so it needs to go from x1,y1
but only be drawn 20% of the way towards x2,y2
The docs don't seem to offer this functionality, is there a way to do this in Fabric already? Or any anyone help with another solution?
Upvotes: 1
Views: 1198
Reputation: 5183
Ye Olde Maths approach:
var line = new fabric.Line([x1, y1, x1 + ((x2 - x1) / 5), y1 + ((y2 - y1) / 5)]
Should get you about 20% there on a straight line.
Upvotes: 2