Advertisement
Kostil_Uranio

Untitled

Jan 29th, 2022
2,029
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.15 KB | None | 0 0
  1. //Аношин Сергей
  2. #include <iostream>
  3. #include <SFML/Graphics.hpp>
  4. #include <cmath>
  5. #include <cstdlib>
  6. #define PI 3,1415
  7.  
  8. using namespace sf;
  9. using namespace std;
  10.  
  11. int WIN_HEIGHT = 720;
  12. int WIN_WIDTH = 1080;
  13. int X_ZERO = WIN_WIDTH / 2;
  14. int Y_ZERO = WIN_HEIGHT / 2;
  15.  
  16. void axes(RenderWindow& window, Font& font) {
  17.     VertexArray axis_x(Lines, 2);
  18.     axis_x[0] = Vector2f(0, Y_ZERO);
  19.     axis_x[1] = Vector2f(WIN_WIDTH, Y_ZERO);
  20.     axis_x[0].color = axis_x[1].color = Color::Black;
  21.  
  22.     VertexArray axis_y(Lines, 2);
  23.     axis_y[0] = Vector2f(X_ZERO, WIN_HEIGHT);
  24.     axis_y[1] = Vector2f(X_ZERO, 0);
  25.     axis_y[0].color = axis_y[1].color = Color::Black;
  26.     /*
  27.     Vertex arrows[6];
  28.     int size = WIN_WIDTH / 100;
  29.     arrows[0] = Vertex(Vector2f(WIN_WIDTH - size, Y_ZERO + size / 2));
  30.     arrows[1] = Vertex(Vector2f(WIN_WIDTH, Y_ZERO));
  31.     arrows[2] = Vertex(Vector2f(WIN_WIDTH - size, Y_ZERO - size / 2));
  32.     arrows[0].color = arrows[1].color = arrows[2].color = Color::Black;
  33.  
  34.     arrows[3] = Vertex(Vector2f(X_ZERO - size / 2, size));
  35.     arrows[4] = Vertex(Vector2f(X_ZERO, 0));
  36.     arrows[5] = Vertex(Vector2f(X_ZERO + size / 2, size));
  37.     arrows[3].color = arrows[4].color = arrows[5].color = Color::Black;
  38.     */
  39.     Text text;
  40.     text.setFont(font);
  41.     text.setString("axis X");
  42.     text.setCharacterSize(16);
  43.     text.setFillColor(Color::Black);
  44.     text.setStyle(Text::Regular);
  45.     text.setPosition(WIN_WIDTH - 50, Y_ZERO + 10);
  46.     window.draw(text);
  47.  
  48.     text.setFont(font);
  49.     text.setString("axis Y");
  50.     text.setCharacterSize(14);
  51.     text.setFillColor(Color::Black);
  52.     text.setStyle(Text::Regular);
  53.     text.setPosition(X_ZERO + 10, 10);
  54.     window.draw(text);
  55.  
  56.     window.draw(axis_x);
  57.     window.draw(axis_y);
  58.     //window.draw(arrows, 6, Triangles);
  59. }
  60.  
  61. void ln(RenderWindow& window, int x_strain, int y_strain, int x_displace, int y_displace) {
  62.     double step = WIN_WIDTH / 1000;
  63.     double k = 10;
  64.     VertexArray ln(LineStrip, 1000);
  65.     for (int i = 0; i < 1000; i++) {
  66.         ln[i].position.x = x_displace + X_ZERO + x_strain * (i * step);
  67.         ln[i].position.y = y_displace + Y_ZERO - y_strain * log(i / k);
  68.         ln[i].color = Color::Red;
  69.     }
  70.     window.draw(ln);
  71.  
  72.  
  73.     /*
  74.     double step = WIN_WIDTH / 300;
  75.     Vertex curve[500];
  76.     double k = 10;
  77.     double t = 50;
  78.     for (int i = 1; i < 500; i++) {
  79.         curve[i] = Vertex(Vector2f((X_ZERO + i * step), (Y_ZERO - t * log(i / k))));
  80.         curve[i].color = Color::Red;
  81.     }
  82.  
  83.     for (int i = 0; i < 500; i++) {
  84.         window.draw(curve, 500, Lines);
  85.     }
  86.     */
  87. }
  88. /*
  89. void net(RenderWindow& window) {
  90.     Vertex line[2];
  91.     double step = 50;
  92.     for (int i = 0; i <= WIN_HEIGHT / step; i++) {
  93.         line[0] = Vertex(Vector2f(0, i * step));
  94.         line[1] = Vertex(Vector2f(WIN_WIDTH, i * step));
  95.         line[0].color = line[1].color = Color(168, 168, 168);
  96.  
  97.         if (i * step != Y_ZERO)
  98.             window.draw(line, 2, Lines);
  99.     }
  100.  
  101.     for (int i = 0; i <= WIN_WIDTH / step; i++) {
  102.         line[0] = Vertex(Vector2f(i * step, 0));
  103.         line[1] = Vertex(Vector2f(i * step, WIN_HEIGHT));
  104.         line[0].color = line[1].color = Color(168, 168, 168);
  105.  
  106.         if (i * step != X_ZERO)
  107.             window.draw(line, 2, Lines);
  108.     }
  109.    
  110. }
  111.  
  112. void show_lab(RenderWindow& window) {
  113.     int Numb_vert = 5;
  114.     double step = (2 * PI) / (Numb_vert + 1);
  115.     int X_ZERO = WIN_WIDTH / 2;
  116.     int Y_ZERO = WIN_HEIGHT / 2;
  117.     int R = 300;
  118.     int r = 30;
  119.     CircleShape circle(r);
  120.     for (int i = 0; i <= Numb_vert; i++) {
  121.         circle.setPosition(X_ZERO + cos(i * step), Y_ZERO - sin(i * step));
  122.         circle.setFillColor(Color(230, 0, 230));
  123.         window.draw(circle);
  124.     }
  125.  
  126. }
  127. */
  128. int main() {
  129.     int x_strain; //1
  130.     int y_strain; //40
  131.  
  132.     cout << "enter x_strain" << endl;
  133.     cin >> x_strain;
  134.  
  135.     cout << "enter y_strain" << endl;
  136.     cin >> y_strain;
  137.  
  138.     int x_displace = 0;
  139.     int y_displace = 0;
  140.  
  141.     RenderWindow window(VideoMode(WIN_WIDTH, WIN_HEIGHT), "Graph");
  142.     Font font;
  143.     if (!font.loadFromFile("Roboto-Black.ttf"))
  144.     {
  145.         cout << "loading error" << endl;
  146.     }
  147.  
  148.  
  149.     while (window.isOpen()) {
  150.         // Конструктор обработчика событий
  151.         Event event;
  152.         while (window.pollEvent(event)) {
  153.             if (event.type == Event::KeyPressed) {
  154.                 if (event.key.code == Keyboard::Right)
  155.                     x_displace += 5;
  156.  
  157.                 if (event.key.code == Keyboard::Left)
  158.                     x_displace += -5;
  159.  
  160.                 if (event.key.code == Keyboard::Up)
  161.                     y_displace += -5;
  162.  
  163.                 if (event.key.code == Keyboard::Down)
  164.                     y_displace += 5;
  165.             }
  166.  
  167.             if (event.type == Event::Closed)
  168.                 window.close();
  169.         }
  170.         // Вызовы функций
  171.         window.clear(Color::White);
  172.         //net(window);
  173.         ln(window, x_strain, y_strain, x_displace, y_displace);
  174.         //show_lab(window);
  175.         axes(window, font);
  176.         window.display();
  177.  
  178.     }
  179.     system("pause");
  180.     return 0;
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement