Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.10 KB | None | 0 0
  1.  
  2. <html>
  3.   <head>
  4.     <title>A canvas fillRect, strokeRect and clearRect example</title>
  5.     <script type="text/javascript">
  6.       var x = 50;
  7.       var y = 0;
  8.       var incX = 2;
  9.       var incY = 2;
  10.       var ancho = 30;
  11.       var alto = 30;
  12.       function drawShape(){        
  13.         var canvas = document.getElementById('tutorial');
  14.           var ctx = canvas.getContext('2d');          
  15.           ctx.clearRect(0,0,150,150);
  16.           ctx.fillRect(x,y,ancho,alto);
  17.           x += incX;
  18.           y += incY;
  19.          
  20.           if(x>120 || x<=0){
  21.             incX*=-1;
  22.           }
  23.           if(y>120 || y<=0){
  24.             incY*=-1;
  25.           }      
  26.          
  27.      }
  28.       setInterval(drawShape,30);
  29.      
  30.    </script>
  31.     <style type="text/css">
  32.       body { margin: 20px; font-family: arial,verdana,helvetica;}
  33.       h1 { font-size: 140%; font-weight:normal; color: #036; border-bottom: 1px solid #ccc; }
  34.       pre { float:left; display:block; background: rgb(238,238,238); border: 1px dashed #666; padding: 15px 20px; margin: 0 0 10px 0; }
  35.     </style>
  36.   </head>
  37.   <body onload="drawShape();">
  38.       <canvas id="tutorial" width="150" height="150"></canvas>
  39.   </body>
  40. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement