Advertisement
Strzyk

Kod na zajecia

Jan 19th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <math.h>
  3. #include <cmath>
  4. #define W 800
  5. #define H 600
  6. #define D 10
  7.  
  8. float* generuj_fib(int ile)
  9. {
  10. float* tmp;
  11. int i;
  12.  
  13. if (ile < 1)
  14. return 0; // warto栺ero jest w C++ r󷮯wana NULL
  15.  
  16. tmp = new float[ile];
  17. // standardowo w przypadku bꤵ new zgasza tak zwany wyjtek - jego obsugi nauczycie si꠷ przyszym semestrze
  18.  
  19.  
  20.  
  21. return tmp;
  22. }
  23.  
  24. int main()
  25. {
  26. float Bx,By,Ax,Ay;
  27. int A=1;
  28. float t;
  29. int i=0;
  30. int f=100; // czestotliwo栈Z
  31. float T=0.1; // s okres
  32. float fp=10000; // czestotliwosc probkowania
  33. float N=T*fp+1; // ilosc kropek na rysunku
  34. float *y;
  35. float *czas;
  36. y= generuj_fib(N);
  37. czas= generuj_fib(N);
  38. Bx=D;
  39. Ax=(W-2*D)/2;
  40. Ay=(H-2*D)/-2*A;
  41. By=D-Ay*A;
  42.  
  43.  
  44. // Create the main window
  45. sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
  46. sf::VertexArray punkty(sf::Points);
  47. for(t=0;t<=T;t+=(1/fp)){
  48. y[i]=A*sin(2*M_PI*f*t);
  49. czas[i]=t;
  50. i++;
  51. }
  52. for(i=0;i<=N;i++){
  53. punkty.append(sf::Vector2f(Ax*czas[i]+Bx,Ay*y[i]+By));
  54. }
  55. sf::VertexArray lines(sf::LinesStrip, 5);
  56. lines[0].position = sf::Vector2f(D, D);
  57. lines[1].position = sf::Vector2f(W-D, D);
  58. lines[2].position = sf::Vector2f(W-D, H-D);
  59. lines[3].position = sf::Vector2f(D, H-D);
  60. lines[4].position = sf::Vector2f(D, D);
  61. // Start the game loop
  62.  
  63. sf::VertexArray ox(sf::LinesStrip, 2);
  64. ox[0].position = sf::Vector2f(D,H/2);
  65. ox[1].position = sf::Vector2f(W-D,H/2);
  66. while (window.isOpen())
  67. {
  68. // Process events
  69. sf::Event event;
  70. while (window.pollEvent(event))
  71. {
  72. // Close window : exit
  73. if (event.type == sf::Event::Closed)
  74. window.close();
  75. }
  76.  
  77. // Clear screen
  78. window.clear();
  79. window.draw(lines);
  80. window.draw(ox);
  81. window.draw(punkty);
  82.  
  83. // Update the window
  84. window.display();
  85. }
  86.  
  87. return EXIT_SUCCESS;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement