I am trying to draw a line with arrow at the tip of the line. But i am unable to complete it. Can any one help me.
I tried adding triangle with line but unfortunately it wont work while dynamically drawing. This is what i tried along with line.
var myPath;
function onMouseDown(event) {
myPath = new Path();
myPath.strokeColor = 'black';
}
function onMouseDrag(event) {
myPath.add(event.point);
}
function onMouseUp(event) {
var myCircle = new Path.RegularPolygon(event.point, 3, 10);
myCircle.strokeColor = 'black';
myCircle.fillColor = 'white';
}
There is an example code in paperjs refrence which draws an arrow at the end of a vector.
Have a look at: http://paperjs.org/tutorials/geometry/vector-geometry/ (scroll all the way down to the end of the page)
Here's an example, where I extend
paper.Group
.In my example I avoid redrawing the arrow on each
mousedrag
. I create once onmousedown
and then transform the line and the arrow parts to the appropriate position/rotation on eachmousedrag
.Note: I'm fairly certain the following code can be improved a lot.
Drawing via mouse events
... or just draw to a static position
If you want to just draw the arrow (without using mouse events), just do the following:
A simple approach is to create a group that consists of the vector itself (the line) and the arrow head.
lineStart
andlineEnd
are the points where the line of the arrow starts and ends.And, as previously mentioned, if you want to recreate it each time then you can make the previous code a function, something like:
Here is a sketch of the previous code sketch.paperjs.org
you draw line with arrow with this code ,
use