Receive all updates via Facebook. Just Click the Like Button Below

Blogger Widgets
/

Watch Intro About My Website ! ! !

Saturday 9 November 2013


The canvas element has no drawing abilities of its own. All drawing must be done inside a JavaScript:

Example Program:

<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas" width="200" height="100"
style="border:1px solid #c3c3c3;">
Your browser does not support the canvas element.
</canvas>

<script type="text/javascript">
var c=document.getElementById("myCanvas");
var cxt=c.getContext("2d");
cxt.fillStyle="#FF0000";
cxt.fillRect(0,0,150,75);
</script>

</body>
</html>

JavaScript uses the id to find the canvas element:

var c=document.getElementById("myCanvas");

Then, create a context object:

var cxt=c.getContext("2d");

The getContext("2d") object is a built-in HTML5 object, with many methods to draw paths, boxes, circles, characters, images and more.

The next two lines draws a red rectangle:

cxt.fillStyle="#FF0000";
cxt.fillRect(0,0,150,75);

The fillStyle method makes it red, and the fillRect method specifies the shape, position, and size.



Tagged: ,

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...