Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Červíky</title>
- <script type="application/javascript">
- function draw() {
- c = document.getElementById('canvas').getContext('2d');
- c.beginPath();
- c.strokeStyle = "red";
- c.lineWidth = 3;
- c.lineCap = "round";
- x = 10;
- y = 10;
- smer = 0.1;
- rychlost = 10;
- c.moveTo(x,y);
- document.onkeypress = function(e){
- var e=window.event || e;
- var pismeno = String.fromCharCode(e.charCode);
- if (pismeno == 'a'){
- smer -= 0.1;
- }
- else if (pismeno == 'd'){
- smer += 0.1;
- }
- }
- refresh = function(){
- x += rychlost * Math.cos(smer);
- y += rychlost * Math.sin(smer);
- c.lineTo(x,y);
- c.stroke();
- setTimeout("refresh()", 50);
- }
- refresh();
- }
- </script>
- </head>
- <body onload="draw()">
- <canvas id="canvas" width="1000" height="600"</canvas>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement