Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html> 
<html>
<head>
<script>
function draw()
{
  var canvas = document.querySelector("#MyCanvas");
    if (canvas.getContext) {
      var ctx = canvas.getContext("2d");
      
      // green rectangle
      ctx.beginPath();
      ctx.strokeStyle="green";  // Use strokeStyle to set the color.
      ctx.rect (5,5,300,250); 
      ctx.stroke();
      
      // eyes
      ctx.beginPath();
      ctx.strokeStyle="blue";  // Use strokeStyle to change the color.
      // Try to change width
      ctx.lineWidth = "5";
      ctx.moveTo(100,100);
      ctx.lineTo(130,100);
      ctx.moveTo(170,100);
      ctx.lineTo(200,100);
      ctx.stroke();
      
      // mouth
      ctx.beginPath();
      ctx.strokeStyle="red";  // Use strokeStyle to change the color.
      ctx.arc(150,125,100,0,Math.PI, false);
      // Try uncommenting the next line !
      //ctx.closePath();
      
      // Try to replace stroke by fill, try to set a color for the FillStyle
      ctx.stroke();
    }  
}
</script>
</head>
  
<body onload="draw();">
  <canvas id="MyCanvas" width="600" height="600"> </canvas> 
</body>
</html>
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers