JSFiddle - React, Tailwind, and code Playground

by 曾田生 曾田生

HTML

<canvas   class="canvas" width="500" height="500" id="canvas"></canvas>

JavaScript

var canvas = document.getElementById('canvas'),   
    context = canvas.getContext('2d');  
   
  context.globalCompositeOperation = 'destination-over';
    context.fillStyle = 'rgb(255,0,0)';
    context.fillRect(0,0,40,40);
    context.fillStyle = 'rgb(0,255,255)';
    context.fillRect(20,20,40,40);
   
    context.globalCompositeOperation = 'source-over';
    context.translate(100,0);
     context.fillStyle = 'rgb(255,0,0)';
    context.fillRect(0,0,40,40);
    context.fillStyle = 'rgb(0,255,255)';
    context.fillRect(20,20,40,40);
 
     context.globalCompositeOperation = 'lighter';
    context.translate(100,0);
     context.fillStyle = 'rgb(255,0,0)';
    context.fillRect(0,0,40,40);
    context.fillStyle = 'rgb(0,255,255)';
    context.fillRect(20,20,40,40);
    
        context.globalCompositeOperation = 'xor';
    context.translate(100,0);
     context.fillStyle = 'rgb(255,0,0)';
    context.fillRect(0,0,40,40);
    context.fillStyle = 'rgb(0,255,255)';
    context.fillRect(20,20,40,40);