Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 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="can" width="1000" height="500" style="position: absolute;"></canvas>
  15. <canvas id="can2" width="1000" height="500" style="position: absolute;"></canvas>
  16. <script>
  17.  
  18.  
  19. var canvas = document.getElementById("can");
  20. var ctx = canvas.getContext("2d");
  21. var canvas2 = document.getElementById("can2");
  22. var ctx2 = canvas2.getContext("2d");
  23.  
  24. //Parametry animacja 2
  25. var parametry=[];
  26. parametry[0]=0;
  27. parametry[1]=0;
  28. var keeper=[];
  29. var ilosc=0;
  30.  
  31.  
  32. function rysuj(){
  33. ctx.beginPath();
  34. ctx.moveTo(520,250);
  35. ctx.lineTo(450,150);
  36. ctx.lineTo(600,150);
  37. ctx.lineTo(520,250);
  38. ctx.lineTo(450,350);
  39. ctx.lineTo(600,350);
  40. ctx.lineTo(520,250);
  41. ctx.strokeStyle="Blue";
  42. ctx.stroke();
  43. ctx.closePath();
  44.  
  45. ctx.beginPath();
  46. ctx.arc(375,285,60,0,Math.PI*2);
  47. ctx.stroke();
  48. ctx.closePath();
  49.  
  50. ctx.beginPath();
  51. ctx.arc(675,316,30,0,Math.PI*2);
  52. ctx.stroke();
  53. ctx.closePath();
  54. }
  55. //Obiekt do animacja 1
  56. class piasek{
  57. constructor(){
  58. this.x=520;
  59. this.y=250;
  60. }
  61.  
  62. ziarnko(){
  63.  
  64. ctx2.beginPath();
  65. ctx2.arc(this.x,this.y,1,0,Math.PI*2);
  66. ctx2.fillStyle="yellow";
  67. ctx2.fill();
  68. ctx2.closePath();
  69. }
  70.  
  71. przesun(){
  72. this.y+=1;
  73. }
  74. }
  75.  
  76. function animacja(){
  77. ctx2.clearRect(0,0,1000,500);
  78. keeper[ilosc] = new piasek();
  79. ilosc+=1;
  80. for(j=0; j<=ilosc; j++){
  81. keeper[j].przesun();
  82. keeper[j].ziarnko();
  83. if(keeper[j].y===311){
  84. delete keeper[j];
  85. keeper[j] = new piasek();
  86. ilosc--;
  87. }
  88. }
  89. }
  90.  
  91. function animacja2(){
  92. ctx.clearRect(0,0,1000,500);
  93. rysuj();
  94. ctx.beginPath();
  95. ctx.moveTo(520,250);
  96. ctx.lineTo(520,190+parametry[0]);
  97. ctx.lineTo(478+parametry[1],190+parametry[0]);
  98. ctx.fillStyle="yellow";
  99. ctx.fill();
  100. ctx.closePath();
  101.  
  102. ctx.beginPath();
  103. ctx.moveTo(520,250);
  104. ctx.lineTo(520,190+parametry[0]);
  105. ctx.lineTo(564-parametry[1],190+parametry[0]);
  106. ctx.fill();
  107. ctx.closePath();
  108.  
  109. ctx.beginPath();
  110. ctx.moveTo(520,350);
  111. ctx.lineTo(520,310-parametry[0]);
  112. ctx.lineTo(564-parametry[1],310-parametry[0]);
  113. ctx.lineTo(600,350);
  114. ctx.fill();
  115. ctx.closePath();
  116.  
  117. ctx.beginPath();
  118. ctx.moveTo(520,350);
  119. ctx.lineTo(520,310-parametry[0]);
  120. ctx.lineTo(478+parametry[1],310-parametry[0]);
  121. ctx.lineTo(450,350);
  122. ctx.fill();
  123. ctx.closePath();
  124.  
  125. parametry[0]+=1;
  126. parametry[1]+=0.75;
  127.  
  128. if(parametry[0]===60){
  129. clearInterval(x);
  130. clearInterval(z);
  131. }
  132. }
  133.  
  134. animacja2();
  135. var x = setInterval(animacja2,700);
  136. var z = setInterval(animacja,10);
  137.  
  138. function restart(){
  139. ilosc=0;
  140. parametry[0]=0;
  141. parametry[1]=0;
  142. var x = setInterval(animacja2,700);
  143. var z = setInterval(animacja,10);
  144. }
  145. </script>
  146. <input type="button" value="Restart" onclick="restart()" style="margin-top: 650px;">
  147. </body>
  148. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement