Advertisement
Guest User

Bloki

a guest
May 23rd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #include <math.h>
  5. #pragma hdrstop
  6.  
  7. #define n 3
  8. #define n1 2
  9. #define amp 4
  10. #define sizeBut 25
  11. #define w 395
  12. #define h 395
  13.  
  14. #include "Unit1.h"
  15. //---------------------------------------------------------------------------
  16. #pragma package(smart_init)
  17. #pragma resource "*.dfm"
  18. TForm1 *Form1;
  19. int vectors[n][n1];
  20. //---------------------------------------------------------------------------
  21. __fastcall TForm1::TForm1(TComponent* Owner)
  22. : TForm(Owner)
  23. {
  24. }
  25. //---------------------------------------------------------------------------
  26.  
  27. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  28. {
  29. if(Button1->Top <= 0)
  30. vectors[0][1] = abs(vectors[0][1]);
  31.  
  32. if(Button1->Top + sizeBut >= h)
  33. vectors[0][1] = -abs(vectors[0][1]);
  34.  
  35. if(Button1->Left + sizeBut >= w)
  36. vectors[0][0] = -abs(vectors[0][0]);
  37.  
  38. if(Button1->Left <= 0)
  39. vectors[0][0] = abs(vectors[0][0]);
  40.  
  41. if(Button2->Top <= 0)
  42. vectors[1][1] = abs(vectors[1][1]);
  43.  
  44. if(Button2->Top + sizeBut >= h)
  45. vectors[1][1] = -abs(vectors[1][1]);
  46.  
  47. if(Button2->Left + sizeBut >= w)
  48. vectors[1][0] = -abs(vectors[1][0]);
  49.  
  50. if(Button2->Left <= 0)
  51. vectors[1][0] = abs(vectors[1][0]);
  52.  
  53. if(Button3->Top <= 0)
  54. vectors[2][1] = abs(vectors[2][1]);
  55.  
  56. if(Button3->Top + sizeBut >= h)
  57. vectors[2][1] = -abs(vectors[2][1]);
  58.  
  59. if(Button3->Left + sizeBut >= w)
  60. vectors[2][0] = -abs(vectors[2][0]);
  61.  
  62. if(Button3->Left <= 0)
  63. vectors[2][0] = abs(vectors[2][0]);
  64.  
  65. int xCen = w / 2, yCen = w / 2, xCen1 = w / 2, yCen1 = w / 2;
  66.  
  67. xCen += Button1->Left;
  68. yCen += Button1->Top;
  69. xCen1 += Button2->Left;
  70. yCen1 += Button2->Top;
  71.  
  72. if(sqrt( abs( (xCen - xCen1) * (xCen - xCen1) ) + abs( (yCen - yCen1) * (yCen - yCen1) ) ) <= sizeBut + 5){
  73. vectors[0][0] = -vectors[0][0];
  74. vectors[0][1] = -vectors[0][1];
  75. }
  76.  
  77. Button1->Top += vectors[0][1];
  78. Button1->Left += vectors[0][0];
  79.  
  80. Button2->Top += vectors[1][1];
  81. Button2->Left += vectors[1][0];
  82.  
  83. Button3->Top += vectors[2][1];
  84. Button3->Left += vectors[2][0];
  85. }
  86. //---------------------------------------------------------------------------
  87. void __fastcall TForm1::FormCreate(TObject *Sender)
  88. {
  89. srand(time(0));
  90. for(int i = 0; i < n; i++){
  91. for(int j = 0; j < n1; j++){
  92. vectors[i][j] = rand() % (amp + 1) - amp;
  93. if(!vectors[i][j])
  94. vectors[i][j] = amp;
  95. }
  96. }
  97. }
  98. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement