Advertisement
qberik

Untitled

May 23rd, 2022
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. /*Задание 1. Построить семейство одинаковых окружностей, центры
  2. которых лежат на окружности большего диаметра.
  3. Задание 2. Окружность должна пульсировать, т. е. периодически
  4. стягиваться в точку и расширяться до внешней.
  5. */
  6. #include <SFML/Graphics.hpp>
  7. #include <vector>
  8. #include <iostream>
  9. #include <cstdlib>
  10. #include <string>
  11. #include <random>
  12. #include <fstream>
  13.  
  14. #define PI 3.14159265358979
  15.  
  16. using namespace sf;
  17. using namespace std;
  18.  
  19.  
  20. int main()
  21. {
  22.  
  23. float h = 800;
  24. float w = 600;
  25. float big_max_radius = 200;
  26. int point_count = 200; // отвечает насколько ровные круги
  27. // full_hd
  28. RenderWindow window(VideoMode( h, w), "SFML works!");
  29.  
  30. // Центральный круг
  31. CircleShape BigCircle( big_max_radius, point_count );
  32. // Посерединке
  33. //BigCircle.setPosition( h / 2, w / 2 );
  34. BigCircle.setPosition( h / 2 - big_max_radius , w / 2 - big_max_radius );
  35. // Красим
  36. BigCircle.setFillColor( Color::Red );
  37.  
  38.  
  39. // массив тех, кто поменьше
  40. vector< CircleShape > circles;
  41.  
  42. // Количество маленьких кругов
  43. int small_count = 6;
  44. // Радиус маленьких гругов
  45. float small_radius = 50;
  46.  
  47. for( int i = 0; i < small_count; i++ ){
  48. CircleShape small( small_radius, point_count );
  49. small.setPosition(
  50. h / 2 + sin( float(i) * 2*PI / small_count ) * big_max_radius - small_radius ,
  51. w / 2 + cos( float(i) * 2*PI / small_count ) * big_max_radius - small_radius
  52. );
  53. circles.push_back( small );
  54. }
  55.  
  56.  
  57. // можно сделать выход по условию
  58. //
  59. int i = 0;
  60. while( true ){
  61. window.clear();
  62. i++;
  63.  
  64.  
  65. float min_radius = 10;
  66. float max_radius = 50;
  67.  
  68. float avg = ( min_radius + max_radius ) / 2;
  69.  
  70. float delta = ( max_radius - min_radius ) / 2;
  71.  
  72. float radius = avg + delta * sin( 0.005 * i );
  73.  
  74. cout << radius << endl;
  75.  
  76.  
  77. window.draw( BigCircle );
  78.  
  79. for( int i = 0; i < small_count; i++ ){
  80. circles[i].setRadius( radius );
  81. circles[i].setPosition(
  82. h / 2 + sin( float(i) * 2*PI / small_count ) * big_max_radius - radius ,
  83. w / 2 + cos( float(i) * 2*PI / small_count ) * big_max_radius - radius
  84. );
  85. window.draw( circles[i] );
  86. }
  87.  
  88.  
  89. window.display();
  90.  
  91. }
  92.  
  93.  
  94. return 0;
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement