Reputation: 83
I am using sketch.js for a project to draw on a canvas. There is a case where I need to do an automatic drawing: that is, I need a way to feed two sets of coordinates-one for where to move to, the other to where to draw to-and have sketch.js to draw the resulting line. Any ideas? I think that startPainting() is a place to start, but I am at a loss on how to send the coordinates. Thank you!
Upvotes: 1
Views: 562
Reputation: 1648
Sketch.js stores all drawing actions which happens on the canvas in a variable called actions.
So you can initialize an action by hand and add this to the array and redraw the sketch.
example function:
function drawLine(xFrom, yFrom, xTo, yTo) {
//get the sketch instance - assumes that your canvas has an id 'simple_sketch'
var s = $('#simple_sketch').sketch();
//initialize the draw action
var action = {
color: "#000000",
events: [{event: 'mousedown', x: xFrom, y: yFrom}, {event: 'mouseup', x: xTo, y:yTo}],
size: 5,
tool: "marker"
};
//push it to the actions array
s.actions.push(action);
//redraw the sketch
s.redraw();
}
Upvotes: 1