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.lineWidth=5;
     ctx.fillStyle='red';
     ctx.strokeStyle='blue'
     // font for all text drawing
     ctx.font = 'italic 20pt Calibri';
     
     // Draw the two filled red rectangles
     ctx.fillRect(10, 30, 70, 150);
     ctx.fillRect(110, 30, 70, 150);
     
     // Draw the two blue wireframe rectangles
     ctx.strokeRect(10, 30, 70, 150);
     ctx.strokeRect(110, 30, 70, 150);
     
     // Draw a message above the rectangles
     ctx.fillText("hello", 70, 22);    
   }
 </script>
 </head>
<body onload="init();">
    <canvas id="myCanvas" width="200" height="200">
            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