Strzyk

sinusoida

Jan 25th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <iostream>
  3. #define H 800
  4. #define W 800
  5. #define D 10
  6. #define pi 3.14159265359
  7. int A = 1;
  8. int f = 10;
  9. float T = 0.1;
  10. float fp = 10000;
  11.  
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16. int xx[] = { D,D,W - D,W - D,D };
  17. int yy[] = { D,H - D,H - D,D,D };
  18.  
  19.  
  20. // Create the main window
  21. sf::RenderWindow window(sf::VideoMode(800, 800), "SFML window");
  22.  
  23.  
  24. sf::VertexArray linie(sf::Lines);
  25. for (int i = 0; i<4; i++)
  26. {
  27. linie.append(sf::Vector2f(xx[i], yy[i])); // poczΔ…tek
  28. linie.append(sf::Vector2f(xx[i + 1], yy[i + 1])); // koniec
  29. };
  30.  
  31. sf::VertexArray wspolrzedne(sf::Lines);
  32. wspolrzedne.append(sf::Vector2f(D, H / 2));
  33. wspolrzedne.append(sf::Vector2f(W - D, H / 2));
  34. int N = T*fp + 1;
  35. float* y;
  36. y = new float[N];
  37. int Bx = D;
  38. int Ax = (W - 2 * D) / T;
  39. int Ay = (H - 2 * D) / (-2 * A);
  40. int By = (D - Ay*A);
  41.  
  42. sf::VertexArray points(sf::Points);
  43. int i = 0;
  44. for (float t = 0; t <= T; t = t + (1/fp)) {
  45. cout << "Pi: " << t << endl;
  46. float x = sin(2 * pi *f*t);
  47. y[i] = (A*x);
  48. points.append(sf::Vector2f(Ax*t + Bx, Ay*y[i] + By));
  49.  
  50. }
  51.  
  52. // Start the game loop
  53. while (window.isOpen())
  54. {
  55. // Process events
  56. sf::Event event;
  57. while (window.pollEvent(event))
  58. {
  59. // Close window : exit
  60. if (event.type == sf::Event::Closed)
  61. window.close();
  62. }
  63.  
  64. // Clear screen
  65. window.clear();
  66. window.draw(linie);
  67. window.draw(wspolrzedne);
  68. window.draw(points);
  69.  
  70. // Update the window
  71. window.display();
  72. }
  73.  
  74. delete[] y;
  75. return EXIT_SUCCESS;
  76. }
Add Comment
Please, Sign In to add comment