Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Ch1Ex3: Your First Canvas Application </title>
- <script src="modernizr-1.6.min.js"></script>
- <script type="text/javascript">
- window.addEventListener("load", eventWindowLoaded, false);
- var Debugger = function () { };
- Debugger.log = function (message) {
- try {
- console.log(message);
- } catch (exception) {
- return;
- }
- }
- function eventWindowLoaded () {
- canvasApp();
- }
- function canvasSupport () {
- return Modernizr.canvas;
- }
- function canvasApp () {
- if (!canvasSupport()) {
- return;
- }
- var theCanvas = document.getElementById("canvasOne");
- var context = theCanvas.getContext("2d");
- Debugger.log("Drawing Canvas");
- function drawScreen() {
- //background
- var myGradient = context.createLinearGradient(0,0,0,200);
- myGradient.addColorStop(0, 'rgb(80,90,150)');
- myGradient.addColorStop(1, 'rgb(140,150,190)');
- context.fillStyle = myGradient; //
- context.fillRect(0, 0, 500, 300);
- context.fillStyle = "#00000";
- context.font = "20px _sans";
- context.textBaseline = "top";
- context.fillText ("'ello World!", 195, 80 );
- context.fillText ("HTML5 YALL!", 185, 190 );
- var helloWorldImage = new Image();
- helloWorldImage.src = "MeSmall.jpg";
- helloWorldImage.onload = function () {
- context.drawImage(helloWorldImage, 200, 100);
- }
- //box
- context.strokeStyle = "#b0bcf2";
- context.strokeRect(5, 5, 490, 290);
- }
- drawScreen();
- }
- </script>
- </head>
- <body>
- <div style="position: absolute; top: 50px; left: 50px;">
- <canvas id="canvasOne" width="500" height="300">
- Your browser does not support HTML 5 Canvas.
- </canvas>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment