How to make move able triangle in canvas js code example
Example 1: How to make move able triangle in canvas js
function drawTrianlge(e) { // add this with event listener...
var bx = fe.offsetX;
var by = fe.offsetY;
var x = e.offsetX;
var y = e.offsetY;
var takeLineLen = Math.abs((bx + by) - (x + y));
context.beginPath();
context.moveTo(bx, by);
context.lineTo(x, y);
context.moveTo(x, y);
context.lineTo(takeLineLen - x / 2 , y);
context.moveTo(takeLineLen - x / 2 , y);
context.lineTo(takeLineLen - y / 2 , by);
context.stroke();
context.closePath();
}
Example 2: How to make move able triangle in canvas js
function drawTrianlge(e) { // add eventlistener!!!
var bx = fe.offsetX;
var by = fe.offsetY;
var x = e.offsetX;
var y = e.offsetY;
context.beginPath();
context.moveTo(bx, y);
context.lineTo(x, y);
context.lineTo(x, by);
context.closePath();
context.stroke();
}