HTML5 canvas using JavaScript

The canvas is HTML5 element used to draw graphics using JavaScript. 

 

[sourcecode language=”plain”]</code><!DOCTYPE html>

<html>

<body>

<canvas id="myCanvas" style="border:1px solid #000000;">Your browser does not support the HTML5 canvas tag.</canvas>

<script>

var c=document.getElementById(‘myCanvas’);

var ctx=c.getContext(‘2d’);

//ctx.fillStyle=’#FF0000′;

for (var x = 0, y = 0; x < 150 && y < 200; x += 50, y += 37) {

var i = x+125;

var color =’FF0’+i;

//alert(color);

ctx.fillStyle=’#’+color;

ctx.fillRect(x,y,60,60);

}

</script>

</body>

</html>

<div> <code>[/sourcecode]


Demo :

Leave a Reply