Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. var ctx = document.getElementById("canvas").getContext("2d");
  2.  
  3. function draw()
  4. {
  5. for (var i = 0; i < 100; i++) {
  6. ctx.beginPath();
  7. ctx.moveTo(20+i*20,0);
  8. ctx.lineTo(20+i*20,800);
  9. ctx.stroke();
  10.  
  11. ctx.beginPath();
  12. ctx.moveTo(0,20+i*20);
  13. ctx.lineTo(600,20+i*20);
  14. ctx.stroke();
  15. }
  16. ctx.Nebo(); //небо
  17. var grad = ctx.createLinearGradient(20, 0, 480, 300);
  18. grad.addColorStop(0, '#B5FBFF');
  19. grad.addColorStop(1, '#2994FF');
  20. ctx.fillStyle = grad;
  21. ctx.fillRect(0, 0, 600, 480);
  22. ctx.fill();
  23.  
  24. ctx.beginPath(); //поле
  25. var grad = ctx.createLinearGradient(0, 800, 0, 500);
  26. grad.addColorStop(0, '#FFC961');
  27. grad.addColorStop(1/2, '#BEF574');
  28. grad.addColorStop(1, '#FFFF66');
  29. ctx.fillStyle = grad;
  30. ctx.fillRect(0, 500, 600, 300);
  31.  
  32. ctx.beginPath(); //дорога у дома
  33. var grad = ctx.createLinearGradient(0, 500, 0, 480);
  34. grad.addColorStop(0, '#DBDBDB');
  35. grad.addColorStop(1, '#BDBDBD');
  36. ctx.fillStyle = grad;
  37. ctx.fillRect(0, 480, 600, 20);
  38.  
  39. ctx.beginPath(); //т. елки
  40. ctx.fillStyle = "rgb(54,99,55)";
  41. ctx.moveTo(140,480);
  42. ctx.lineTo(140,160);
  43. ctx.lineTo(200,480);
  44. ctx.fill();
  45.  
  46. ctx.beginPath(); //круглая елка
  47. ctx.arc(540, 400, 80, 0, Math.PI*2, true);
  48. ctx.fillStyle = "rgb(54,99,55)";
  49. ctx.fill();
  50.  
  51. ctx.beginPath(); //стена
  52. ctx.fillStyle = "rgb(250,250,250)";
  53. ctx.fillRect(240,320,80,160);
  54. ctx.fillStyle = "rgb(205,205,205)";
  55. ctx.fillRect(320,320,80,160);
  56. ctx.fillStyle = "rgb(205,205,205)";
  57. ctx.fillRect(400,420,180,60);
  58. ctx.fillStyle = "rgb(250,250,250)";
  59. ctx.fillRect(140,400,100,80);
  60.  
  61. ctx.beginPath(); //окошки и дверь
  62. ctx.fillStyle = "rgb(86,63,31)";
  63. ctx.fillRect(280,340,20,40);
  64. ctx.fillStyle = "rgb(86,63,31)";
  65. ctx.fillRect(260,420,40,60);
  66. ctx.fillStyle = "rgb(86,63,31)";
  67. ctx.fillRect(360,340,20,40);
  68. ctx.fillStyle = "rgb(86,63,31)";
  69. ctx.fillRect(500,440,10,20);
  70. ctx.fillStyle = "rgb(86,63,31)";
  71. ctx.fillRect(540,440,10,20);
  72. ctx.fillStyle = "rgb(86,63,31)";
  73. ctx.fillRect(160,420,10,20);
  74. ctx.fillStyle = "rgb(86,63,31)";
  75. ctx.fillRect(200,420,10,20);
  76.  
  77. ctx.beginPath(); //газон у дома
  78. var grad = ctx.createLinearGradient(400, 470, 400, 480);
  79. grad.addColorStop(0, 'green');
  80. grad.addColorStop(1, '#363636');
  81. ctx.fillStyle = grad;
  82. ctx.fillRect(400, 470, 180, 10);
  83.  
  84. ctx.beginPath(); //крыша
  85. ctx.fillStyle = "rgb(220,57,19)";
  86. ctx.moveTo(240,320);
  87. ctx.lineTo(320,240);
  88. ctx.lineTo(320,320);
  89. ctx.fill();
  90.  
  91. ctx.beginPath();
  92. ctx.fillStyle = "rgb(173,46,14)";
  93. ctx.moveTo(320,240);
  94. ctx.lineTo(400,320);
  95. ctx.lineTo(320,320);
  96. ctx.fill();
  97.  
  98. ctx.fillStyle = "rgb(220,57,19)";
  99. ctx.fillRect(400,360,160,60);
  100.  
  101. ctx.beginPath(); //крыша
  102. ctx.fillStyle = "rgb(173,46,14)";
  103. ctx.moveTo(400,420);
  104. ctx.lineTo(400,360);
  105. ctx.lineTo(480,360);
  106. ctx.fill();
  107.  
  108. ctx.beginPath();
  109. ctx.fillStyle = "rgb(220,57,19)";
  110. ctx.moveTo(560,360);
  111. ctx.lineTo(580,420);
  112. ctx.lineTo(560,420);
  113. ctx.fill();
  114.  
  115. ctx.fillStyle = "rgb(220,57,19)";
  116. ctx.fillRect(160,340,80,60);
  117.  
  118. ctx.beginPath();
  119. ctx.fillStyle = "rgb(220,57,19)";
  120. ctx.moveTo(140,400);
  121. ctx.lineTo(160,340);
  122. ctx.lineTo(160,400);
  123. ctx.fill();
  124.  
  125. ctx.beginPath(); //св. елки
  126. ctx.fillStyle = "rgb(67,152,70)";
  127. ctx.moveTo(80,480);
  128. ctx.lineTo(140,160);
  129. ctx.lineTo(140,480);
  130. ctx.fill();
  131.  
  132. ctx.beginPath(); // св. елки
  133. ctx.fillStyle = "rgb(67,152,70)";
  134. ctx.moveTo(40,480);
  135. ctx.lineTo(80,120);
  136. ctx.lineTo(80,480);
  137. ctx.fill();
  138.  
  139. ctx.beginPath(); //т. елки
  140. ctx.fillStyle = "rgb(54,99,55)";
  141. ctx.moveTo(80,480);
  142. ctx.lineTo(80,120);
  143. ctx.lineTo(120,480);
  144. ctx.fill();
  145. }
  146.  
  147. function snowdrawing()
  148. {
  149. clear();
  150. ctx.beginPath();
  151. if (positionXx < 1500) {
  152. positionXx += 2;
  153. } else
  154. {
  155. positionXx = 10;
  156. positionY = 10;
  157. }
  158. for (var i = 0; i <= 400; i++) {
  159. var x = Math.round(Math.random() * 1000),
  160. y = Math.round(Math.random() * 1000);
  161. ctx.beginPath();
  162. ctx.fillStyle = "rgba(255,255,255,0.4)";
  163. ctx.arc(x, y + positionY, 5, 0, Math.PI * 2, true);
  164. ctx.fill();
  165. ctx.beginPath();
  166. ctx.fill();
  167. ctx.closePath();
  168. }
  169. setInterval(drawing,100);
  170. var positionXxx = 0;
  171. var positionY = 0;
  172. var positionXx = 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement