Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.83 KB | None | 0 0
  1. <html>
  2.  <head>
  3.  <title>Červíky</title>
  4.   <script type="application/javascript">
  5.  
  6. function draw() {
  7.     c = document.getElementById('canvas').getContext('2d');
  8.  
  9.     c.beginPath();
  10.     c.strokeStyle = "red";
  11.     c.lineWidth = 3;
  12.     c.lineCap = "round";
  13.     x = 10;
  14.     y = 10;
  15.     smer = 0.1;
  16.     rychlost = 10;
  17.     c.moveTo(x,y);
  18.  
  19.     document.onkeypress = function(e){
  20.         var e=window.event || e;
  21.         var pismeno = String.fromCharCode(e.charCode);
  22.         if (pismeno == 'a'){
  23.             smer -= 0.1;
  24.         }
  25.         else if (pismeno == 'd'){
  26.             smer += 0.1;
  27.         }
  28.     }
  29.  
  30.     refresh = function(){
  31.         x += rychlost * Math.cos(smer);
  32.         y += rychlost * Math.sin(smer);
  33.         c.lineTo(x,y);
  34.         c.stroke();
  35.         setTimeout("refresh()", 50);
  36.     }
  37.  
  38.     refresh();
  39. }
  40.  
  41.  
  42.   </script>
  43.  </head>
  44.  <body onload="draw()">
  45.    <canvas id="canvas" width="1000" height="600"</canvas>
  46.  </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement