Canvas 2D API의 CanvasRenderingContext2D.globalCompositeOperation 속성은 새 모양을 그릴 때 적용할 합성 작업의 유형을 설정한다.
그림과 그림이 겹칠 때 겹치는 부분에 대한 유형을 설정하는 것이라고 생각하면 된다.!
아래와 같이 사용하면 된다.
ctx.globalCompositeOperation = type;
types의 종류는 다음과 같다.
const ctx = document.getElementById('canvas').getContext('2d');
function draw(){
//도형이 겹칠때 속성을 설정한다.
ctx.globalCompositeOperation = 'lighten';
ctx.fillStyle = 'blue';
ctx.fillRect(10,10,100,100);
ctx.fillStyle = 'red';
ctx.fillRect(50,50,100,100);
ctx.fillStyle = 'green';
ctx.fillRect(70,0,100,100);
}
if(document.getElementById('canvas').getContext){
draw();
}