CENMMOS.PAS 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. Uses Crt,Graph,MyTPU,F_mouse;
  2. Const
  3. MaxPoints = 15;
  4. Path = '';
  5. StepPixel = 20;
  6. Type TPoints = record
  7. x,y,massa : Word;
  8. end;
  9. Var
  10. points : array[1..MaxPoints] of ^TPoints;
  11. center : PointType;
  12. circles : array [1..9] of Pointer;
  13. Size : array [1..9] of Word;
  14. CenterM :Pointer;
  15. SizeC : Word;
  16. mod_num : Word;
  17. num_of_point,numdelpoint : byte;
  18. CounterPoints : byte;
  19. Butt : Integer;
  20. ch : char;
  21. i,x0,y0 : Integer;
  22. SaveF : File of tpoints;
  23. {-------------------------------------------}
  24. Procedure Recenter;forward;
  25. {----------------------------------------------}
  26. Function GetFreePoint:Byte;
  27. Var
  28. i:byte;
  29. Begin
  30. GetFreePoint := 0;
  31. for i := 1 to MaxPoints do if points[i]^.massa = 0 then GetFreePoint := i;
  32. End;{GetFreePoint}
  33. {-------------------------------------------}
  34. Procedure NewPoint(num:byte);
  35. Var
  36. Xm,Ym : Integer;
  37. Begin
  38. MouseWhereXY(Xm,Ym);
  39. HideMouse;
  40. points[num]^.x := Xm;
  41. points[num]^.y := ym;
  42. points[num]^.massa := GetValue('Введите массу точки от 1 до 9',Xm,Ym,1,9);
  43. PutImage(points[num]^.x-Points[num]^.massa,points[num]^.y-Points[num]^.massa,
  44. circles[Points[num]^.massa]^,XorPut);
  45. Recenter;
  46. Inc(CounterPoints);
  47. ShowMouse;
  48. End;{NewPoint}
  49. {-------------------------------------------}
  50. Procedure DelPoint(Num:byte);
  51. Begin
  52. HideMouse;
  53. PutImage(points[num]^.x-points[num]^.massa,
  54. points[num]^.y-points[num]^.massa,Circles[points[num]^.massa]^,XorPut);
  55. With Points[num]^ do begin
  56. x := 0;
  57. y := 0;
  58. massa :=0;
  59. end;
  60. Dec(CounterPoints);
  61. ReCenter;
  62. ShowMouse;
  63. End;{DelPoint}
  64. {------------------------------------------}
  65. Function TestPos(x1,y1:Integer) : boolean;
  66. Var
  67. i:integer;
  68. begin
  69. TestPos := true;
  70. for i := 1 to MaxPoints do
  71. with Points[i]^ do if (x1=x) and (y1=y) then TestPos:=false;
  72. end;
  73. {----------------------------------------------}
  74. Procedure FindCenter;
  75. Var
  76. i:Integer;
  77. summaX,SummaY,smas:real;
  78. Begin
  79. if counterPoints <> 0 then begin
  80. SummaX:=0;
  81. SummaY:=0;
  82. Smas:=0;
  83. for i:= 1 to MaxPoints do if points[i]^.massa <> 0 then
  84. begin
  85. summaX := SummaX + points[i]^.massa * points[i]^.x;
  86. summaY := SummaY + points[i]^.massa * points[i]^.Y;
  87. smas := smas + points[i]^.massa;
  88. end;
  89. center.x := round(summaX/smas);
  90. center.y := round(summaY/smas);
  91. End;
  92. End;{FindCenter}
  93. {--------------------------------------------}
  94. Procedure SetPoints;
  95. Var
  96. i,x1,y1,massa1 : Integer;
  97. Begin
  98. for i := 1 to MaxPoints do
  99. begin
  100. New(points[i]);
  101. repeat
  102. begin
  103. Y1 := random(410)+10;
  104. X1 := random(490)+10;
  105. massa1 := random(8)+1;
  106. end;
  107. until TestPos(x1,y1);
  108. with points[i]^ do
  109. begin
  110. x := x1;
  111. y := y1;
  112. massa := massa1;
  113. end;
  114. inc(CounterPoints);
  115. end;
  116. End;{SetPoints}
  117. {-----------------------------------------}
  118. Procedure WriteTbl;
  119. Var i : byte;
  120. Begin
  121. SetLineStyle(SolidLn,1,3);
  122. SetColor(Blue);
  123. Rectangle(1,1,500,420);
  124. SetFillStyle(SolidFill,LightGray);
  125. SetTextJustify(CenterText,TopText);
  126. for i := 1 to 5 do Bar(515,i*70-20,625,i*70+30);
  127. OutTextXY(570,65,'Сменить');
  128. OutTextXY(570,80,'точки');
  129. OutTextXY(570,130,'Стереть');
  130. OutTextXY(570,155,'траекторию');
  131. OutTextXY(570,215,'Сохранить');
  132. OutTextXY(570,280,'Загрузить');
  133. OutTextXY(570,350,'Выход');
  134. {-------===Ввод поинтеров=======---------}
  135. SetColor(White);
  136. SetLineStyle(SolidLn,1,1);
  137. for i := 1 to 9 do
  138. begin
  139. Circle(100,100,i);
  140. Size[i] := ImageSize(100-i,100-i,100+i,100+i);
  141. GetMem(circles[i],Size[i]);
  142. GetImage(100-i,100-i,100+i,100+i,circles[i]^);
  143. PutImage(100-i,100-i,circles[i]^,XORput);
  144. end;
  145. SetFillStyle(SolidFill,Red);
  146. FillEllipse(100,100,4,4);
  147. SizeC := ImageSize(96,96,104,104);
  148. GetMem(CenterM,SizeC);
  149. GetImage(96,96,104,104,CenterM^);
  150. PutImage(96,96,CenterM^,XORPut);
  151. end;{WriteTbl}
  152. {---------------------------------------------}
  153. Procedure ReCenter;
  154. Begin
  155. PutImage(center.X-4,center.Y-4,CenterM^,XORPut);
  156. FindCenter;
  157. PutImage(center.X-4,center.Y-4,CenterM^,XORPut);
  158. End;{ReCenter}
  159. {--------------------------------------------}
  160. Procedure MovePoint(n:byte;x,y:Integer);
  161. Var
  162. s1,s2,s3:string;
  163. Begin
  164. PutImage(points[n]^.x-points[n]^.massa,points[n]^.y-points[n]^.massa,
  165. Circles[points[n]^.massa]^,XORPut);
  166. if x+points[n]^.massa > 499 then x := 499 - points[n]^.massa;
  167. if y+points[n]^.massa > 419 then y := 419 - points[n]^.massa;
  168. if X-points[n]^.massa < 2 then x := 2 + points[n]^.massa;
  169. if Y-points[n]^.massa < 2 then y := 2 + points[n]^.massa;
  170. points[n]^.x := x;
  171. points[n]^.Y := Y;
  172. SetFillStyle(SolidFill,Black);
  173. Bar(100,430,300,450);
  174. Str(x,s1);
  175. Str(y,s2);
  176. Str(points[n]^.massa,s3);
  177. s1 := s1+' '+s2+' '+s3;
  178. OutTextXY(220,440,s1);
  179. PutImage(points[n]^.x-points[n]^.massa,points[n]^.y-points[n]^.massa,
  180. Circles[points[n]^.massa]^,XORPut);
  181. PutImage(center.x-4,center.y-4, CenterM^,XORPut);
  182. PutPixel(Center.x,Center.Y,Yellow);
  183. FindCenter;
  184. PutImage(center.x-4,center.y-4, CenterM^,XORPut);
  185. End;{MovePoint}
  186. {------------------------------}
  187. Function TestCircles(var circle_num :byte):boolean;
  188. Var
  189. i : byte;
  190. Begin
  191. TestCircles := false;
  192. for i := 1 to MaxPoints do if MouseIn(points[i]^.X-points[i]^.massa,
  193. points[i]^.y-points[i]^.massa,
  194. points[i]^.X+points[i]^.massa,
  195. points[i]^.y+points[i]^.massa)
  196. then begin
  197. circle_num :=i;
  198. TestCircles :=true;
  199. end;
  200. End;{TestCircles}
  201. {------------------------------------}
  202. Procedure EXITp;
  203. var i : byte;
  204. Begin
  205. For i := 1 to MaxPoints do Dispose(Points[i]);
  206. For i := 1 to 9 do FreeMem(circles[i],size[i]);
  207. FreeMem(CenterM,SizeC);
  208. CloseGraph;
  209. Halt(1)
  210. End;{EXITp}
  211. {-----------------------------------------}
  212. Function GetEvent:byte;
  213. var
  214. value : byte;
  215. Begin
  216. value := 0;
  217. GetMouseState(Butt,x0,y0);
  218. case butt of
  219. 1: begin
  220. if TestCircles(Num_of_point) then value := 6;
  221. if MouseIn(515, 50,625,100) then value :=1;
  222. if MouseIn(515,120,625,170) then value :=2;
  223. if MouseIn(515,190,625,240) then value :=3;
  224. if MouseIn(515,260,625,310) then value :=4;
  225. if MouseIn(515,330,625,380) then value :=5;
  226. if (value = 0) and mousein(2,2,500,420) and (GetFreePoint <> 0) then
  227. value := 7;
  228. end;
  229. 2: if TestCircles(NumDelPoint) then value := 8;
  230. end;
  231. GetEvent := value;
  232. End;{GetEvent}
  233. {------------------------------------------}
  234. Procedure RandomPoints;
  235. Begin
  236. HideMouse;
  237. for i := 1 to MaxPoints do PutImage(points[i]^.x-points[i]^.massa,
  238. points[i]^.y-points[i]^.massa,
  239. Circles[points[i]^.massa]^,XorPut);
  240. SetFillStyle(SolidFill,Black);
  241. Bar(2,2,499,419);
  242. SetPoints;
  243. for i := 1 to MaxPoints do PutImage(points[i]^.x-points[i]^.massa,
  244. points[i]^.y-points[i]^.massa,
  245. Circles[points[i]^.massa]^,XorPut);
  246. FindCenter;
  247. PutImage(center.X-4,center.Y-4,CenterM^,XORPut);
  248. ShowMouse;
  249. End;{RandomPoints}
  250. {-----------------------------------------}
  251. Procedure Save;
  252. Var i :Byte;
  253. Begin
  254. {$I-}
  255. REWrite(SaveF);
  256. {$I+}
  257. if IOResult <> 0 then
  258. Exit
  259. else
  260. for i:= 1 to 10 do
  261. begin
  262. Seek(SaveF,i);
  263. Write(SaveF,Points[i]^);
  264. end;
  265. Close(SaveF);
  266. End;{Save}
  267. {-----------------------------------------}
  268. Procedure Load;
  269. Var i :byte;
  270. Begin
  271. {$I-}
  272. Reset(SaveF);
  273. {$I+}
  274. if IOResult <> 0 then
  275. else
  276. begin
  277. HideMouse;
  278. for i := 1 to MaxPoints do PutImage(points[i]^.x-points[i]^.massa,
  279. points[i]^.y-points[i]^.massa,
  280. Circles[points[i]^.massa]^,XorPut);
  281. SetFillStyle(SolidFill,Black);
  282. Bar(2,2,499,419);
  283. for i := 1 to 10 do
  284. begin
  285. Seek(SaveF,i);
  286. Read(SaveF,Points[i]^);
  287. end;
  288. for i := 1 to MaxPoints do PutImage(points[i]^.x-points[i]^.massa,
  289. points[i]^.y-points[i]^.massa,
  290. Circles[points[i]^.massa]^,XorPut);
  291. end;
  292. FindCenter;
  293. PutImage(center.X-4,center.Y-4,CenterM^,XORPut);
  294. ShowMouse;
  295. Close(SaveF);
  296. End;{Load}
  297. {-----------------------------------------}
  298. Begin {MAIN Program}
  299. Assign(SaveF,'center.tbl');
  300. CounterPoints:=0;
  301. Randomize;
  302. InitVGA;
  303. WriteTbl;
  304. SetPoints;
  305. for i := 1 to MaxPoints do PutImage(points[i]^.x-points[i]^.massa,
  306. points[i]^.y-points[i]^.massa,
  307. Circles[points[i]^.massa]^,XorPut);
  308. ReCenter;
  309. Mouse;
  310. SetStepToPixel(StepPixel,StepPixel);
  311. MouseWindow(2,2,630,420);
  312. repeat
  313. case getEvent of
  314. 6 : begin
  315. HideMouse;
  316. MouseGotoXY(points[num_of_point]^.x,points[num_of_point]^.y);
  317. repeat
  318. MouseWhereXY(x0,y0);
  319. MovePoint(Num_of_point,X0,Y0);
  320. Until Not MousePressed;
  321. ShowMouse
  322. end;
  323. 7: NewPoint(GetFreePoint);
  324. 8: DelPoint(NumDelPoint);
  325. 1: RandomPoints;
  326. 2: begin
  327. HideMouse;
  328. for i := 1 to MaxPoints do PutImage(points[i]^.x-points[i]^.massa,
  329. points[i]^.y-points[i]^.massa,
  330. Circles[points[i]^.massa]^,XorPut);
  331. PutImage(center.X-4,center.Y-4,CenterM^,XORPut);
  332. SetFillStyle(SolidFill,Black);
  333. Bar(2,2,499,419);
  334. for i := 1 to MaxPoints do PutImage(points[i]^.x-points[i]^.massa,
  335. points[i]^.y-points[i]^.massa,
  336. Circles[points[i]^.massa]^,XorPut);
  337. PutImage(center.X-4,center.Y-4,CenterM^,XORPut);
  338. ShowMouse;
  339. end;
  340. 3: Save;
  341. 4: load;
  342. 5: Exitp;
  343. end;
  344. if keypressed then ch := readkey;
  345. if ch = #27 then ExitP;
  346. until false;
  347. End.