Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8. <head>
  9. <title>TODO supply a title</title>
  10. <meta charset="UTF-8">
  11. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  12. </head>
  13. <body>
  14. <canvas id="canv" width="1000" height="600"></canvas>
  15. <script>
  16. var c = document.getElementById("canv");
  17. var ctx = c.getContext("2d");
  18.  
  19. class sniezka {
  20. constructor(x,y,r)
  21. {
  22. this.x=x;
  23. this.y=y;
  24. this.r=r;
  25. }
  26.  
  27. sniezynka()
  28. {
  29. ctx.beginPath();
  30.  
  31. ctx.moveTo(this.x-this.r, this.y);
  32. ctx.lineTo(this.x+this.r, this.y);
  33.  
  34. ctx.moveTo(this.x, this.y-this.r);
  35. ctx.lineTo(this.x, this.y+this.r);
  36.  
  37. ctx.moveTo(this.x-this.r, this.y+this.r);
  38. ctx.lineTo(this.x+this.r, this.y-this.r);
  39.  
  40. ctx.moveTo(this.x+this.r, this.y+this.r);
  41. ctx.lineTo(this.x-this.r, this.y-this.r);
  42.  
  43. ctx.stroke();
  44. ctx.closePath();
  45. }
  46.  
  47. przesun(dx, dy)
  48. {
  49. this.dx=dx;
  50. this.dy=dy;
  51.  
  52. this.x += this.dx;
  53. this.y += this.dy;
  54.  
  55. ctx.clearRect(0,0,1000,600);
  56.  
  57. this.sniezynka();
  58. }
  59.  
  60. };
  61.  
  62. var zm = new sniezka(20,20,10);
  63. zm.sniezynka();
  64. zm.przesun(40,20);
  65. </script>
  66. </body>
  67. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement