To prevent overlapping semi-transparent pixels from interacting, you can convert the semi-transparent pixels (in RGBA format) to equivalent opaque pixels (in RGB format).
function RGBAtoRGB(r, g, b, a, backgroundR,backgroundG,backgroundB){
var r3 = Math.round(((1 - a) * backgroundR) + (a * r))
var g3 = Math.round(((1 - a) * backgroundG) + (a * g))
var b3 = Math.round(((1 - a) * backgroundB) + (a * b))
return "rgb("+r3+","+g3+","+b3+")";
}
For each sub-shape, it is important to use a separate beginPath
. This ensures that each shape has its own styling (fillStyle) per beginpath.
Depending on your specific design needs, you may need to adjust the drawing order of your sub-shapes so that the desired opaque shapes are displayed on top.