The Basic File Setup for This Chapter
As we proceed through the Drawing API, all the examples in this chapter
will use the same basic file setup, shown below. Use this code as the
basis for all of the examples we create. You will have to change only the
contents of the drawScreen()
function:
<!doctype html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
Ch2BaseFile - Template For Chapter 2 Examples</title>
<
script
src
=
"modernizr.js"
><
/script>
<
script
type
=
"text/javascript"
>
window
.
addEventListener
(
'load'
,
eventWindowLoaded
,
false
);
function
eventWindowLoaded
()
{
canvasApp
();
}
function
canvasSupport
()
{
return
Modernizr
.
canvas
;
}
function
canvasApp
(){
if
(
!
canvasSupport
())
{
return
;
}
else
{
var
theCanvas
=
document
.
getElementById
(
"canvas"
);
var
context
=
theCanvas
.
getContext
(
"2d"
);
}
drawScreen
();
function
drawScreen
()
{
//make changes here.
context
.
fillStyle
=
'#aaaaaa'
;
context
.
fillRect
(
0
,
0
,
200
,
200
);
context
.
fillStyle
=
'#000000'
;
context
.
font
=
'20px _sans'
;
context
.
textBaseline
=
'top'
;
context
.
fillText
(
"Canvas!"
,
0
,
0
);
}
}
<
/script>
</head>
<body>
<div
style=
"position: absolute; top: 50px; left: 50px;"
>
<canvas
id=
"canvas"
width=
"500"
height=
"500"
>
Your browser does not support HTML5 Canvas.</canvas>
</div>
</body>
</html>
Get HTML5 Canvas, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.