Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Задание 1. Построить семейство одинаковых окружностей, центры
- которых лежат на окружности большего диаметра.
- Задание 2. Окружность должна пульсировать, т. е. периодически
- стягиваться в точку и расширяться до внешней.
- */
- #include <SFML/Graphics.hpp>
- #include <vector>
- #include <iostream>
- #include <cstdlib>
- #include <string>
- #include <random>
- #include <fstream>
- #define PI 3.14159265358979
- using namespace sf;
- using namespace std;
- int main()
- {
- float h = 800;
- float w = 600;
- float big_max_radius = 200;
- int point_count = 200; // отвечает насколько ровные круги
- // full_hd
- RenderWindow window(VideoMode( h, w), "SFML works!");
- // Центральный круг
- CircleShape BigCircle( big_max_radius, point_count );
- // Посерединке
- //BigCircle.setPosition( h / 2, w / 2 );
- BigCircle.setPosition( h / 2 - big_max_radius , w / 2 - big_max_radius );
- // Красим
- BigCircle.setFillColor( Color::Red );
- // массив тех, кто поменьше
- vector< CircleShape > circles;
- // Количество маленьких кругов
- int small_count = 6;
- // Радиус маленьких гругов
- float small_radius = 50;
- for( int i = 0; i < small_count; i++ ){
- CircleShape small( small_radius, point_count );
- small.setPosition(
- h / 2 + sin( float(i) * 2*PI / small_count ) * big_max_radius - small_radius ,
- w / 2 + cos( float(i) * 2*PI / small_count ) * big_max_radius - small_radius
- );
- circles.push_back( small );
- }
- // можно сделать выход по условию
- //
- int i = 0;
- while( true ){
- window.clear();
- i++;
- float min_radius = 10;
- float max_radius = 50;
- float avg = ( min_radius + max_radius ) / 2;
- float delta = ( max_radius - min_radius ) / 2;
- float radius = avg + delta * sin( 0.005 * i );
- cout << radius << endl;
- window.draw( BigCircle );
- for( int i = 0; i < small_count; i++ ){
- circles[i].setRadius( radius );
- circles[i].setPosition(
- h / 2 + sin( float(i) * 2*PI / small_count ) * big_max_radius - radius ,
- w / 2 + cos( float(i) * 2*PI / small_count ) * big_max_radius - radius
- );
- window.draw( circles[i] );
- }
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement