I have three arrys:
clickX = [], clickY = [], clickDrag = [];
this is what happens when you click down:
$('#canvasCursor').mousedown(function (e) { console.log('down'); mouseX = e.pageX - this.offsetLeft; mouseY = e.pageY - this.offsetTop; paint = true; addClick(e.pageX - this.offsetLeft, e.pageY - this.offsetTop); redraw(); });
here it adds clicks to the array and draws .:
function redraw () {ctx.clearRect (0, 0, ctx.canvas.width, ctx.canvas.height); // Removes the canvas
ctx.strokeStyle = "green"; ctx.lineJoin = "round"; ctx.lineWidth = brushSize*2; for (var i = 0; i < clickX.length; i++) { ctx.beginPath(); if (clickDrag[i] && i) { ctx.moveTo(clickX[i - 1], clickY[i - 1]); } else { ctx.moveTo(clickX[i] - 1, clickY[i]); } ctx.lineTo(clickX[i], clickY[i]); ctx.closePath(); ctx.stroke(); } }
I am trying to get rid of the way the array does it now, because when I change var brushSize dynamically with the slider, it redraws the whole image in a new size, not the size that they had at that time. I don't know how to save the size of any particular object in an array, and then draw it separately.
I do not mind if I cannot implement the undo function, which in this way gives me as long as I can fix the brush resizing. Here you can see what I'm chatting about! http://www.taffatech.com/Paint.html
- also seems to be slower and I guess it because its drawing from an array
source share