lavalevel

HTML5 - Hello World

Nov 26th, 2011
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.78 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Ch1Ex3: Your First Canvas Application </title>
  6. <script src="modernizr-1.6.min.js"></script>
  7. <script type="text/javascript">
  8. window.addEventListener("load", eventWindowLoaded, false); 
  9.  
  10.  
  11. var Debugger = function () { };
  12. Debugger.log = function (message) {
  13.     try {
  14.         console.log(message);
  15.     } catch (exception) {
  16.         return;
  17.     }
  18. }
  19.  
  20.  
  21. function eventWindowLoaded () {
  22.     canvasApp();
  23. }
  24.  
  25. function canvasSupport () {
  26.     return Modernizr.canvas;
  27. }
  28.  
  29. function canvasApp () {
  30.        
  31.         if (!canvasSupport()) {
  32.              return;
  33.         }
  34.        
  35.         var theCanvas = document.getElementById("canvasOne");
  36.         var context = theCanvas.getContext("2d");
  37.        
  38.        
  39.         Debugger.log("Drawing Canvas");
  40.  
  41.        
  42.         function drawScreen() {
  43.             //background
  44.             var myGradient = context.createLinearGradient(0,0,0,200);
  45.            
  46.             myGradient.addColorStop(0, 'rgb(80,90,150)');
  47.             myGradient.addColorStop(1, 'rgb(140,150,190)');
  48.            
  49.             context.fillStyle = myGradient; //
  50.             context.fillRect(0, 0, 500, 300);
  51.  
  52.             context.fillStyle    = "#00000";
  53.             context.font         = "20px _sans";
  54.             context.textBaseline = "top";
  55.             context.fillText  ("'ello World!", 195, 80 );
  56.             context.fillText  ("HTML5 YALL!", 185, 190 );
  57.        
  58.             var helloWorldImage = new Image();
  59.             helloWorldImage.src = "MeSmall.jpg";
  60.             helloWorldImage.onload = function () {
  61.                 context.drawImage(helloWorldImage, 200, 100);
  62.             }
  63.             //box
  64.             context.strokeStyle = "#b0bcf2";
  65.             context.strokeRect(5,  5, 490, 290);
  66.            
  67.         }
  68.        
  69.         drawScreen();
  70.  
  71.        
  72. }
  73.  
  74.  
  75. </script>
  76. </head>
  77. <body>
  78. <div style="position: absolute; top: 50px; left: 50px;">
  79. <canvas id="canvasOne" width="500" height="300">
  80.  Your browser does not support HTML 5 Canvas.
  81. </canvas>
  82. </div>
  83. </body>
  84. </html>
  85.  
  86.  
  87.  
  88.  
  89.  
Advertisement
Add Comment
Please, Sign In to add comment