Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
   <div>
        <canvas id="myCanvas" width="300" height="150">
            <p>Your browser doesn't support canvas.</p>
        </canvas>
    </div>
</body>
</html>
 
function drawCanvas() {
    // Get our Canvas element
    var surface = document.getElementById("myCanvas");
    if (surface.getContext) {
        // If Canvas is supported
        var ctx = surface.getContext('2d');
        // Set the clipping area
       // draw rectangle
    ctx.fillStyle = "#09f";
    ctx.fillRect(15,15,70,70);
      
    // set composite property
    ctx.globalCompositeOperation = "source-in";
    
    // draw circle
   ctx.fillStyle = "black";
    ctx.fillText("WWWWWWWWW",15,15+16);
      
      ctx.globalCompositeOperation = "source-over";
      
      ctx.fillStyle = "red";
    ctx.fillRect(60,60,70,70);
      
    }
}
drawCanvas();
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers