Hello everyone, I have a problem here.
I do a small drawing and on the task I need to draw lines with different levels of transparency on the canvas. Here is an example of such a drawing:
https://jsfiddle.net/08cw6mh7/
var canvas = document.getElementById('paint'); var ctx = canvas.getContext('2d'); var radius = 10; var drag= false; canvas.width = window.innerWidth; canvas.height = window.innerHeight; $("#paint").mousedown(function(e){ drag = true; }); $("#paint").mousemove(function(e){ if (drag){ ctx.lineWidth = radius*2; ctx.strokeStyle="rgba(50,100,150,.25)" ctx.lineTo(e.clientX, e.clientY); ctx.stroke(); ctx.beginPath(); ctx.arc(e.clientX, e.clientY, radius, 0, Math.PI*2); ctx.fillStyle="rgba(50,100,150,.25)" ctx.fill(); ctx.beginPath(); ctx.moveTo(e.clientX, e.clientY) } }); $("#paint").mouseup(function(e){ drag = false ; }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <canvas id="paint" style="display: block"></canvas> The problem is the following: if you draw the fill color for example rgba (50, 100, 150, 1) then everything works well as transparency 1. And when you move the mouse, the colors, although superimposed on each other, are not noticeable due to the total opacity. But if you start to change the transparency for example rgba (50, 100, 150, .25), then trash starts - the colors begin to overlap and it turns out not a uniformly transparent line, but it is not clear what. What can be done?