Currently I have a canvas where you can draw a square with your cursor like paint.net. As you drag your cursor it will create a square starting from the left corner. I wish for it to start at the center of the square instead. Is it possible to achieve this with rect ?
The code below draws a square starting from the left corner where mouseCoords is the starting point where your cursor started dragging and currentMouse is the location where you have dragged to.
//create rectangle starting from left corner
canvas.getContext('2d').rect(
mouseCoords.x,
mouseCoords.y,
currentMouse.x - mouseCoords.x,
currentMouse.y - mouseCoords.y
);