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() {
     // draw a red rectangle
     ctx.fillStyle='lightgreen';
     ctx.fillRect(0,0,100,200);
     ctx.fillRect(150,0,100,200);
     ctx.fillRect(300,0,100,200);
   }
 </script>
 </head>
<body onload="init();">
    <canvas id="myCanvas" width="400" height="400">
            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