Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
 <head>
 <style>
     #myCanvas {
         border: 1px solid black;
     }
 </style>
 <script>
   var canvas, ctx;
 
   function init() {
     // This function is called after the page is loaded
     // 1 - Get the canvas
     canvas = document.getElementById('myCanvas');
     // 2 - Get the context
     ctx=canvas.getContext('2d');
     // 3 - we can draw
     drawSomething();
   }
   function drawSomething() {
     // set the global context values
     ctx.fillStyle='rgba(0, 0, 255, 0.2)';
     // Draw the two filled red rectangles
     ctx.fillRect(150, 20, 200, 100);
     ctx.fillRect(100, 50, 200, 100);
     
     ctx.fillStyle = "blue";
     ctx.fillRect(50, 100, 200, 100);
   }
 </script>
 </head>
<body onload="init();">
    <canvas id="myCanvas" width="400" height="220">
            Your browser does not support the canvas tag.
    </canvas>
</body>
</html>
Output

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

Dismiss x
public
Bin info
micbuffapro
0viewers