Friday, January 20, 2012

HTML5 canvas, with example of fillRect()

HTML5 canvas, with example of fillRect()
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mobile-Web-App: HTML5 Canvas</title>
<script type="text/javascript">
function loadcanvas(){
var canvas;
var context;

//get element by ID of "mycanvas"
canvas = document.getElementById("mycanvas");

//create a "2d" context object
context = canvas.getContext("2d");

context.fillStyle = "#A0A0A0";
context.fillRect(20, 20, 360, 260); //( X, Y, WIDTH, HEIGHT)

context.fillStyle = "#505050";
context.fillRect(50, 50, 300, 200);
context.fillStyle = "#000000";
context.fillRect(200, 150, 50, 50);
}
</script>
</head>
<body onload="loadcanvas();">
<h1>Mobile-Web-App: HTML5 canvas</h1>

<canvas id="mycanvas" style="border: 5px solid;" width="400" height="300">
Sorry! Your browser doesn't support Canvas.
</canvas>
</body>
</html>

No comments:

Post a Comment