Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. program snake;
  2. uses crt, graph;
  3. var graphicsdriver,graphicsmode:smallint;
  4. entry,active,n,count,s,r:integer;
  5. x,y:array of integer;
  6. b:array[1..2] of integer;
  7.  
  8. procedure varinit;
  9. begin
  10. b[1] := 1000;
  11. b[2] := 600;
  12. end;
  13.  
  14. procedure opgr;
  15. begin
  16. active := 1;
  17. graphicsdriver := detect;
  18. initgraph(graphicsdriver, graphicsmode,'');
  19. end;
  20.  
  21. procedure clgr;
  22. begin
  23. active := 0;
  24. closegraph;
  25. end;
  26.  
  27. procedure valout;
  28. begin
  29. textcolor(lightred);
  30. write('* Please enter a number within the defined parameters. ');
  31. textcolor(yellow);
  32. write('[1..6]');
  33. writeln();
  34. textcolor(lightgray);
  35. end;
  36.  
  37. procedure coordout;
  38. begin
  39. textcolor(lightred);
  40. write('* Your entered coordinate is out of the border. ');
  41. textcolor(yellow);
  42. write('[',b[1],' x ',b[2],']');
  43. writeln();
  44. textcolor(lightgray);
  45. end;
  46.  
  47. procedure border;
  48. begin
  49. rectangle(0,0,b[1],b[2]);
  50. end;
  51.  
  52. procedure xyvals;
  53. begin
  54. count := n;
  55. for n := 1 to count do
  56. begin
  57. repeat
  58. textcolor(lightgray);
  59. write('Please enter the value of ');
  60. textcolor(white);
  61. write('x');
  62. textcolor(yellow);
  63. write('[',n,']');
  64. textcolor(lightgray);
  65. if n = 1 then
  66. begin
  67. textcolor(lightgreen);
  68. write(' (the origin coordinates).');
  69. textcolor(lightgray);
  70. end
  71. else
  72. begin
  73. write('.');
  74. end;
  75. writeln();
  76. readln(x[n]);
  77. if (x[n] < 1) or (x[n] > (b[1]-1)) then
  78. begin
  79. coordout;
  80. end;
  81. until (x[n] > 0) and (x[n] < b[1]);
  82. //
  83. repeat
  84. textcolor(lightgray);
  85. write('Please enter the value of ');
  86. textcolor(white);
  87. write('y');
  88. textcolor(yellow);
  89. write('[',n,']');
  90. textcolor(lightgray);
  91. if n = 1 then
  92. begin
  93. textcolor(lightgreen);
  94. write(' (the origin coordinates).');
  95. textcolor(lightgray);
  96. end
  97. else
  98. begin
  99. write('.');
  100. end;
  101. writeln();
  102. readln(y[n]);
  103. if (y[n] < 1) or (y[n] > (b[2]-1)) then
  104. begin
  105. coordout;
  106. end;
  107. until (y[n] > 0) and (y[n] < b[2])
  108. end;
  109. end;
  110.  
  111. procedure tri;
  112. begin
  113. n := 3;
  114. setlength(x, n);
  115. setlength(y, n);
  116. xyvals;
  117. opgr;
  118. border;
  119. line(x[1],y[1],x[2],y[2]);
  120. line(x[2],y[2],x[3],y[3]);
  121. line(x[3],y[3],y[1],y[1]);
  122. delay(3000);
  123. clgr;
  124. end;
  125.  
  126. procedure rect;
  127. begin
  128. n := 2;
  129. setlength(x, n);
  130. setlength(y, n);
  131. xyvals;
  132. opgr;
  133. border;
  134. rectangle(x[1],y[1],x[2],y[2]);
  135. delay(3000);
  136. clgr;
  137. end;
  138.  
  139. procedure squ;
  140. begin
  141. n := 1;
  142. setlength(x, n);
  143. setlength(y, n);
  144. xyvals;
  145. repeat
  146. writeln('Please enter the side length of the square.');
  147. readln(s);
  148. if ((x[1]+s) > (b[1]-1)) or ((y[1])+s > (b[2]-1)) or ((x[1]-s) < 1) or ((y[1]-s) < 1) then
  149. begin
  150. textcolor(lightred);
  151. write('* Your entered side length causes the square to exceed the border. ');
  152. textcolor(yellow);
  153. write('[',b[1],' x ',b[2],']');
  154. writeln();
  155. textcolor(lightgray);
  156. end;
  157. until ((x[1])+s < b[1]) and ((y[1])+s < b[2]) and ((x[1]-s) > 0) and ((y[1]-s) > 0);
  158. opgr;
  159. border;
  160. rectangle(x[1],y[1],x[1]+s,y[1]+s);
  161. delay(3000);
  162. clgr;
  163. end;
  164.  
  165. procedure circ;
  166. begin
  167. n := 1;
  168. setlength(x, n);
  169. setlength(y, n);
  170. xyvals;
  171. repeat
  172. writeln('Please enter the radius of the circle.');
  173. readln(r);
  174. if ((x[1]+r) > (b[1]-1)) or ((y[1])+r > (b[2]-1)) or ((x[1]-r) < 1) or ((y[1]-r) < 1) then
  175. begin
  176. textcolor(lightred);
  177. write('* Your entered radius causes the circle to exceed the border. ');
  178. textcolor(yellow);
  179. write('[',b[1],' x ',b[2],']');
  180. writeln();
  181. textcolor(lightgray);
  182. end;
  183. until ((x[1])+r < b[1]) and ((y[1])+r < b[2]) and ((x[1]-r) > 0) and ((y[1]-r) > 0);
  184. opgr;
  185. border;
  186. circle(x[1],y[1],r);
  187. delay(3000);
  188. clgr;
  189. end;
  190.  
  191. procedure scr;
  192. begin
  193.  
  194. end;
  195.  
  196. procedure proc;
  197. begin
  198. case entry of
  199. 1:tri;
  200. 2:rect;
  201. 3:squ;
  202. 4:circ;
  203. 5:scr;
  204. 6:halt(0);
  205. end;
  206. end;
  207.  
  208. procedure menu;
  209. begin
  210. textcolor(lightgray);
  211. writeln('1. Draw Triangle');
  212. writeln('2. Draw Rectangle');
  213. writeln('3. Draw Square');
  214. writeln('4. Draw Circle');
  215. writeln('5. Screensaver');
  216. textcolor(lightmagenta);
  217. writeln('6. EXIT');
  218. textcolor(lightgray);
  219. writeln();
  220. repeat
  221. write('Please enter your option ');
  222. textcolor(lightcyan);
  223. write('[1..6]');
  224. writeln();
  225. textcolor(lightgray);
  226. readln(entry);
  227. if (entry < 1) or (entry > 6) then
  228. begin
  229. valout;
  230. end;
  231. until (entry > 0) and (entry < 7);
  232. end;
  233.  
  234. begin
  235. varinit;
  236. while true do
  237. begin
  238. clrscr;
  239. menu;
  240. proc;
  241. end;
  242. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement