Advertisement
Rize13

Lab8 PW

Apr 21st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. //EX1
  2. <html>
  3. <head>
  4. <title>lab8</title>
  5. </head>
  6.  
  7. <body>
  8. <canvas id="canvas" width="600" height="600"></canvas>
  9. <script>
  10.  
  11.  
  12. //Exemplu lab:
  13. /* var canvas = document.getElementById("canvas");
  14. var ctx = canvas.getContext("2d");
  15. for (var i=0; i<8; i++) {
  16. ctx.fillRect( i *10, i*10, 10, 10);
  17. }
  18. */
  19. // exercitiu 1
  20.  
  21. var canvas = document.getElementById("canvas");
  22. var ctx = canvas.getContext("2d");
  23. for (var i=0; i<1; i++){
  24. ctx.fillRect(70, 0, 60, 60);
  25. ctx.fillRect(95, 60, 10, 30);
  26. ctx.fillRect(0, 90, 200, 10);
  27. ctx.fillRect(45, 100, 100, 100);
  28. ctx.fillRect(45, 100, 100, 100);
  29. ctx.fillRect(45, 200, 20, 85);
  30. ctx.fillRect(125, 200, 20, 85);
  31. }
  32. </script>
  33. </body>
  34. </html>
  35.  
  36. //EX2
  37. <html>
  38. <head>
  39. <title>lab8</title>
  40. </head>
  41.  
  42. <body>
  43. <canvas id="canvas" width="600" height="600"></canvas>
  44. <script>
  45.  
  46. //exercitiu 2
  47. var canvas = document.getElementById("canvas");
  48. var ctx = canvas.getContext("2d");
  49. for (var i=0; i<1; i++){
  50. ctx.fillRect(0, 0, 100, 50);
  51. ctx.fillStyle = "#008B8B";
  52. ctx.fillRect(0, 50, 100, 50);
  53. ctx.fillStyle = "#DC143C";
  54. ctx.fillRect(100, 0, 100, 50);
  55. ctx.fillStyle = "#E9967A";
  56. ctx.fillRect(100, 50, 100, 50);
  57. ctx.fillStyle = "#8FBC8F"
  58. }
  59.  
  60. </script>
  61. </body>
  62. </html>
  63.  
  64. //EX3
  65. <html>
  66. <head>
  67. <title>lab8</title>
  68. </head>
  69.  
  70. <body>
  71. <canvas id="canvas" width="600" height="600"></canvas>
  72. <script>
  73.  
  74. //exemplu cercuri colorate
  75.  
  76. /* var canvas = document.getElementById("canvas");
  77. var ctx = canvas.getContext("2d");
  78.  
  79. var circle = function (x, y, radius){
  80. ctx.beginPath();
  81. ctx.arc(x, y, radius, 0, Math.PI *2, false);
  82. ctx.stroke();
  83. };
  84. ctx.lineWidth = 4;
  85.  
  86. ctx.strojkeStyle = "Red";
  87. circle(100, 100, 10);
  88. ctx.strokeStyle = "Orange";
  89. circle(100, 100, 20);
  90. ctx.strokeStyle = "Yellow";
  91. circle(100, 100, 30);
  92. ctx.strokeStyle = "Green";
  93. circle(100, 100, 40);
  94. ctx.strokeStyle = "Blue";
  95. circle(100, 100, 50);
  96. ctx.strokeStyle = "Purple";
  97. circle(100, 100, 60);
  98. */
  99.  
  100. //exercitiul3
  101.  
  102. var canvas = document.getElementById("canvas");
  103. var ctx = canvas.getContext("2d");
  104. ctx.strokeStyle = "#008000";
  105. ctx.lineWidth = 4;
  106. ctx.strokeRect(30, 4, 20, 20);
  107.  
  108. ctx.beginPath()
  109. ctx.moveTo(40, 24);
  110. ctx.lineTo(40, 100);
  111. ctx.stroke();
  112.  
  113. ctx.beginPath()
  114. ctx.moveTo(40, 60);
  115. ctx.lineTo(20, 30);
  116. ctx.stroke();
  117.  
  118. ctx.beginPath()
  119. ctx.moveTo(40, 60);
  120. ctx.lineTo(60, 30);
  121. ctx.stroke();
  122.  
  123. ctx.beginPath()
  124. ctx.moveTo(40, 100);
  125. ctx.lineTo(20, 130);
  126. ctx.stroke();
  127.  
  128. ctx.beginPath()
  129. ctx.moveTo(40, 100);
  130. ctx.lineTo(60, 130);
  131. ctx.stroke()
  132.  
  133. </script>
  134. </body>
  135. </html>
  136.  
  137. //EX4
  138. <html>
  139. <head>
  140. <title>lab8</title>
  141. </head>
  142.  
  143. <body>
  144. <canvas id="canvas" width="600" height="600"></canvas>
  145. <script>
  146.  
  147. //exercitiul4
  148.  
  149. var canvas = document.getElementById("canvas");
  150. var ctx = canvas.getContext("2d");
  151. ctx.lineWidth = 4;
  152. var circle = function (x, y, radius, foo) {
  153. ctx.beginPath();
  154. ctx.arc(x, y, radius, 0, Math.PI * 2, false);
  155. ctx.stroke();
  156. if (foo === true) {
  157. ctx.fill();
  158. }
  159. };
  160.  
  161. //corp
  162. circle(200,100,40,false);
  163. circle(200,200,60,false);
  164. //nas
  165. ctx.fillStyle = "Orange";
  166. ctx.strokeStyle = "Orange";
  167. circle(200,110,5,true);
  168. //ochi si nasturi
  169. ctx.fillStyle = "Black";
  170. ctx.strokeStyle = "Black";
  171. circle(185,93,5,true);
  172. circle(215,93,5,true);
  173. circle(200,200,5,true);
  174. circle(200,170,5,true);
  175. circle(200,230,5,true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement