Advertisement
Fhernd

Using Canvas

May 29th, 2012
1,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.63 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!-- From: Wiley HTML5 for Dummies Quick Reference (2011)  -->
  3. <html lang="en">
  4.     <head>
  5.         <meta charset="UTF-8"/>
  6.         <title>Canvas example</title>
  7.         <script language="JavaScript" type="text/javascript" >
  8.             function draw ()
  9.             {
  10.                 var myCanvas = document.getElementById( "myCanvas");
  11.                 var context = myCanvas.getContext( "2d");
  12.                
  13.                 context.fillStyle = "blue";
  14.                 context.strokeStyle = "red";
  15.                
  16.                 circle( context, 1, 1, 1 );
  17.                
  18.                 for( i = 1; i <= 200; i+= 2 )
  19.                {
  20.                    circle( context, i, i, "blue" );
  21.                    circle( context, 300-i, 200-i, i, "red" );
  22.                    circle( context, 300-i, i, i, "blue" );
  23.                    circle( context, i, 200-i, i, "red" );
  24.                } // end for
  25.            } // end draw
  26.            
  27.            function circle ( context, x, y, radius, color )
  28.            {
  29.                context.strokeStyle = color;
  30.                context.beginPath();
  31.                context.arc( x, y, radius, 0, Math.PI * 2, true );
  32.                context.stroke();
  33.            } // end circle
  34.        </script>
  35.     </head>
  36.     <body>
  37.         <br/>
  38.         <canvas id="myCanvas"
  39.                width="300"
  40.                height="200">
  41.             This example requieres HTML5 canvas support.
  42.         </canvas>
  43.        
  44.         <button type="button"
  45.                onclick="draw()">
  46.                 click me to see a drawing
  47.         </button>
  48.     </body>
  49. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement