I have that drawing logic:
Draw = function(canvas, ctx, mousePosition) {
var grad = ctx.createLinearGradient(0, 0, canvas[0].width, 0);
grad.addColo
Yes, that is to be expected as each line is overdrawn at the connection points, and their alpha data will add up.
I would suggest the following approach and attach a proof-of-concept demo at the end, feel free to adopt that code to your project:
globalAlpha=1
globalAlpha
on main canvas equal the CSS opacity of top canvasdrawImage()
.var draft = document.getElementById("draft");
var main = document.getElementById("main");
var ctx = draft.getContext("2d");
var mctx = main.getContext("2d");
var isDown = false, prev, alpha = 0.4;
// setup pen
ctx.strokeStyle = "rgb(0,200,127)";
ctx.lineWidth = 16;
ctx.lineCap = "round"; // important to make lines cont.
// set up alpha
draft.style.opacity = alpha; // CSS alpha for draft
mctx.globalAlpha = alpha; // context alpha for main
draft.onmousedown = function(e){
isDown = true;
prev = getXY(e); // set prev. point as start
};
window.onmousemove = function(e){
if (!isDown) return;
var point = getXY(e);
ctx.beginPath(); // new path
ctx.moveTo(prev.x, prev.y); // start at prev. point
ctx.lineTo(point.x, point.y); // line to new point
ctx.stroke(); // stroke
prev = point; // update prev. point
};
window.onmouseup = function(){
isDown = false; // when up:
mctx.drawImage(draft, 0, 0); // copy drawing to main
ctx.clearRect(0, 0, draft.width, draft.height); // clear draft
};
function getXY(e) {
var r = draft.getBoundingClientRect();
return {x: e.clientX - r.left, y: e.clientY - r.top}
}
#draft {cursor:crosshair}
.sandwich {position:relative}
.sandwich>canvas {position:absolute;left:0;top:0}