Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <SFML/Graphics.hpp>
- using namespace sf;
- const int SCREEN_WIDTH = 900;
- const int SCREEN_HEIGHT = 700;
- void update(sf::VertexArray v);
- sf::VertexArray interpolation(sf::Quads, 4);
- float bottomright = SCREEN_WIDTH / 2;
- float bottomleft = bottomright;
- bool positivedirection = true;
- int main()
- {
- const float FPS = 60.0f; //The desired FPS. (The number of updates each second).
- bool redraw = true; //Do I redraw everything on the screen?
- sf::RenderWindow window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32), "My window");
- window.setFramerateLimit(FPS);
- sf::Clock clock;
- // define the position of the triangle's points
- interpolation[0].position = sf::Vector2f((SCREEN_WIDTH * 0.1), (SCREEN_HEIGHT * 0.1)); //Top Left 10 10
- interpolation[1].position = sf::Vector2f((SCREEN_WIDTH * 0.9), (SCREEN_HEIGHT * 0.1)); //Top Right 100 10
- interpolation[2].position = sf::Vector2f(bottomright, (SCREEN_HEIGHT * 0.9)); //bottom right 100 100
- interpolation[3].position = sf::Vector2f(bottomleft, (SCREEN_HEIGHT * 0.9));
- // define the color of the triangle's points
- interpolation[0].color = sf::Color::Red;
- interpolation[1].color = sf::Color::Blue;
- interpolation[2].color = sf::Color::Green;
- interpolation[3].color = sf::Color::Yellow;
- while (window.isOpen())
- {
- sf::Event event;
- //Wait until 1/60th of a second has passed, then update everything.
- if (clock.getElapsedTime().asSeconds() >= 1.0f / FPS)
- {
- redraw = true; //We're ready to redraw everything
- clock.restart();
- }
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- }
- // redraws according to the 60 fps check
- if (redraw)
- {
- redraw = false;
- window.clear(sf::Color::Black);
- update(interpolation);
- window.draw(interpolation);
- window.display();
- }
- redraw = true;
- }
- return 0;
- }
- void update(sf::VertexArray v) {
- if (bottomright > (SCREEN_WIDTH * 0.9) && bottomleft < (SCREEN_WIDTH * 0.1))
- {
- positivedirection = false;
- }
- if (bottomright <(SCREEN_WIDTH/2) && bottomleft > (SCREEN_WIDTH/2))
- {
- positivedirection = true;
- }
- if (positivedirection)
- {
- // interpolate on a vertex to make it looks like a quad becoming a triangle
- interpolation[2].position = sf::Vector2f(bottomright += 1, (SCREEN_HEIGHT * 0.9)); //bottom right 100 100
- interpolation[3].position = sf::Vector2f(bottomleft -=1 , (SCREEN_HEIGHT * 0.9));
- }
- else if (!positivedirection)
- {
- // interpolate on a vertex to make it looks like a quad becoming a triangle
- interpolation[2].position = sf::Vector2f(bottomright -= 1, (SCREEN_HEIGHT * 0.9)); //bottom right 100 100
- interpolation[3].position = sf::Vector2f(bottomleft += 1, (SCREEN_HEIGHT * 0.9));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement