how to get current x and y of canvas context code example
Example 1: get item position in canvas
function Rectangle(props){
var posX = this.posX = props.x;
var posY = this.posY = props.y;
this.width = props.width;
this.height = props.height;
this.fill = props.fill;
this.draw = function(){
ctx.fillStyle = this.fill;
ctx.fillRect(this.posX, this.posY, this.width, this.height);
}
}
Example 2: javascript canvas ground zero
let c = document.getElementById("my_canvas");
let ctx = c.getContext("2d");
ctx.fillStyle = "red";
ctx.strokeStyle = "#ecf0f1";
let ctx = c.getContext("2d");
ctx.beginPath();
ctx.moveTo(50,50);
ctx.lineTo(200,200);
ctx.moveTo(200,50);
ctx.lineTo(50,200);
ctx.closePath();
ctx.lineJoin = "bevel";
ctx.lineCap = "round";
ctx.fillRect(x, y, width, height);
ctx.arc(x, y, radius, startAngle, Math.PI, flow(true/false));
ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, destx, desty);
ctx.quadraticCurveTo(cp1x, cp1y, destx, desty);