Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <math.h>
- #include <cmath>
- #define W 800
- #define H 600
- #define D 10
- float* generuj_fib(int ile)
- {
- float* tmp;
- int i;
- if (ile < 1)
- return 0; // warto栺ero jest w C++ rwana NULL
- tmp = new float[ile];
- // standardowo w przypadku bꤵ new zgasza tak zwany wyjtek - jego obsugi nauczycie si꠷ przyszym semestrze
- return tmp;
- }
- int main()
- {
- float Bx,By,Ax,Ay;
- int A=1;
- float t;
- int i=0;
- int f=100; // czestotliwo栈Z
- float T=0.1; // s okres
- float fp=10000; // czestotliwosc probkowania
- float N=T*fp+1; // ilosc kropek na rysunku
- float *y;
- float *czas;
- y= generuj_fib(N);
- czas= generuj_fib(N);
- Bx=D;
- Ax=(W-2*D)/2;
- Ay=(H-2*D)/-2*A;
- By=D-Ay*A;
- // Create the main window
- sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
- sf::VertexArray punkty(sf::Points);
- for(t=0;t<=T;t+=(1/fp)){
- y[i]=A*sin(2*M_PI*f*t);
- czas[i]=t;
- i++;
- }
- for(i=0;i<=N;i++){
- punkty.append(sf::Vector2f(Ax*czas[i]+Bx,Ay*y[i]+By));
- }
- sf::VertexArray lines(sf::LinesStrip, 5);
- lines[0].position = sf::Vector2f(D, D);
- lines[1].position = sf::Vector2f(W-D, D);
- lines[2].position = sf::Vector2f(W-D, H-D);
- lines[3].position = sf::Vector2f(D, H-D);
- lines[4].position = sf::Vector2f(D, D);
- // Start the game loop
- sf::VertexArray ox(sf::LinesStrip, 2);
- ox[0].position = sf::Vector2f(D,H/2);
- ox[1].position = sf::Vector2f(W-D,H/2);
- while (window.isOpen())
- {
- // Process events
- sf::Event event;
- while (window.pollEvent(event))
- {
- // Close window : exit
- if (event.type == sf::Event::Closed)
- window.close();
- }
- // Clear screen
- window.clear();
- window.draw(lines);
- window.draw(ox);
- window.draw(punkty);
- // Update the window
- window.display();
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement