Bolonka

Untitled

Jul 6th, 2023
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <windows.h>
  5.  
  6. #define SPACE_SIZE 51
  7. #define INDENT 15
  8.  
  9. struct space_point_str {
  10. int x;
  11. int y;
  12.  
  13. char type;
  14. };
  15.  
  16. struct square_point_srt {
  17. float x;
  18. float y;
  19.  
  20. float start_x;
  21. float start_y;
  22. };
  23.  
  24. int main()
  25. {
  26.  
  27. const int add = (SPACE_SIZE-1)/2; // величина смещения координат точек
  28.  
  29. const int space_area = SPACE_SIZE*SPACE_SIZE;
  30. const int square_size = (SPACE_SIZE - 2*INDENT);
  31. const int square_area = ( (SPACE_SIZE - 2*INDENT)*(SPACE_SIZE - 2*INDENT) );
  32.  
  33. float angle = 0;
  34.  
  35. // Инициализация точек пространства
  36. struct space_point_str space_point[space_area];
  37. for(int i=0;i<space_area;i++) {
  38. space_point[i].x = (i%SPACE_SIZE)-add;
  39. space_point[i].y = (i/SPACE_SIZE)-add;
  40. space_point[i].type = 'Q';
  41. }
  42.  
  43. //Инициализация точек квадрата
  44. struct square_point_srt square_point[square_area];
  45. for(int i=0;i<square_area;i++) {
  46. square_point[i].x = (i%square_size)-add+INDENT;
  47. square_point[i].y = (i/square_size)-add+INDENT;
  48.  
  49. square_point[i].start_x = square_point[i].x;
  50. square_point[i].start_y = square_point[i].y;
  51. }
  52.  
  53.  
  54. while (1) {
  55.  
  56. system("cls");
  57. ///// Поворот относительно центра квадрата
  58. angle += 0.1;
  59.  
  60. for(int i=0;i<square_area;i++) {
  61. square_point[i].x = ( square_point[i].start_x*cos(angle) ) - ( square_point[i].start_y*sin(angle) );
  62. square_point[i].y = ( square_point[i].start_y*cos(angle) ) + ( square_point[i].start_x*sin(angle) );
  63.  
  64. }
  65.  
  66. ///// Отрисовка квадрата
  67. int xx,yy;
  68. for(int i=0;i<space_area;i++) {
  69. for(int ii=0;ii<square_area;ii++) {
  70. xx = (int)round(square_point[ii].x); // Округляется x
  71. yy = (int)round(square_point[ii].y); // Округляется y
  72. if( (space_point[i].x == xx) && (space_point[i].y == yy) ) {
  73. space_point[i].type = '1';
  74. break;
  75. }
  76. else {
  77. space_point[i].type = ' ';
  78. }
  79. }
  80.  
  81. if ( (i%SPACE_SIZE) == 0) {
  82. printf("\n");
  83. }
  84. printf("%c ",space_point[i].type);
  85. }
  86.  
  87. ///// Пауза между циклами
  88. usleep(2000);
  89.  
  90. }
  91.  
  92.  
  93. } // конец мейн функции
  94.  
Advertisement
Add Comment
Please, Sign In to add comment