html canvas javascript info code example

Example 1: javascritp canvas

//Creates a canvas and draws a circle
var canvas = document.body.appendChild(document.createElement("canvas"));
var ctx = canvas.getContext("2d");

ctx.beginPath();
ctx.arc(canvas.width / 2, canvas.height / 2, 50, 0, Math.PI * 2);
ctx.fillStyle = "red";
ctx.strokeStyle = "black";
ctx.stroke();
ctx.fill();

Example 2: canvas in javascript

<!DOCTYPE HTML>

<html>
   <head>
   
      <style>
         #mycanvas{border:1px solid red;}
      </style>
   </head>
   
   <body>
      <canvas id = "mycanvas" width = "100" height = "100"></canvas>
   </body>
</html>

Tags:

Html Example