Using destination-over on HTML5 canvas

Example of how you can use the destination-over global composite operation on the HTML5 canvas.
<!DOCTYPE html>
<html>
<head>
</head>  
<body>
<canvas id="myCanvas" width="600" height="300"></canvas>
<script>
    
    var ctx = document.getElementById('myCanvas').getContext('2d');
    
 // draw a simple rectangle shape
    ctx.fillStyle = "#FF0000";
    ctx.fillRect(18,18,75,75);

 // set the composite property shape
    ctx.globalCompositeOperation = 'destination-over';
    
 // draw a simple circle shape
    ctx.fillStyle = "#0066FF";
    ctx.beginPath();
    ctx.arc(80,80,45,0,Math.PI*2,true);
    ctx.fill();
    
</script>
</body>
</html>

Responses

0 Replies