Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <SFML/Graphics.hpp>
  3.  
  4. using namespace sf;
  5.  
  6. const int SCREEN_WIDTH = 900;
  7. const int SCREEN_HEIGHT = 700;
  8.  
  9. void update(sf::VertexArray v);
  10.  
  11. sf::VertexArray interpolation(sf::Quads, 4);
  12.  
  13. float bottomright = SCREEN_WIDTH / 2;
  14. float bottomleft = bottomright;
  15. bool positivedirection = true;
  16.  
  17. int main()
  18. {
  19. const float FPS = 60.0f; //The desired FPS. (The number of updates each second).
  20. bool redraw = true; //Do I redraw everything on the screen?
  21.  
  22. sf::RenderWindow window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32), "My window");
  23. window.setFramerateLimit(FPS);
  24. sf::Clock clock;
  25.  
  26. // define the position of the triangle's points
  27. interpolation[0].position = sf::Vector2f((SCREEN_WIDTH * 0.1), (SCREEN_HEIGHT * 0.1)); //Top Left 10 10
  28. interpolation[1].position = sf::Vector2f((SCREEN_WIDTH * 0.9), (SCREEN_HEIGHT * 0.1)); //Top Right 100 10
  29. interpolation[2].position = sf::Vector2f(bottomright, (SCREEN_HEIGHT * 0.9)); //bottom right 100 100
  30. interpolation[3].position = sf::Vector2f(bottomleft, (SCREEN_HEIGHT * 0.9));
  31.  
  32. // define the color of the triangle's points
  33. interpolation[0].color = sf::Color::Red;
  34. interpolation[1].color = sf::Color::Blue;
  35. interpolation[2].color = sf::Color::Green;
  36. interpolation[3].color = sf::Color::Yellow;
  37.  
  38.  
  39.  
  40.  
  41. while (window.isOpen())
  42. {
  43. sf::Event event;
  44.  
  45. //Wait until 1/60th of a second has passed, then update everything.
  46. if (clock.getElapsedTime().asSeconds() >= 1.0f / FPS)
  47. {
  48. redraw = true; //We're ready to redraw everything
  49. clock.restart();
  50. }
  51.  
  52. while (window.pollEvent(event))
  53. {
  54.  
  55. if (event.type == sf::Event::Closed)
  56. window.close();
  57. }
  58.  
  59.  
  60. // redraws according to the 60 fps check
  61. if (redraw)
  62. {
  63. redraw = false;
  64.  
  65. window.clear(sf::Color::Black);
  66.  
  67. update(interpolation);
  68. window.draw(interpolation);
  69. window.display();
  70. }
  71.  
  72.  
  73. redraw = true;
  74. }
  75.  
  76. return 0;
  77. }
  78.  
  79.  
  80. void update(sf::VertexArray v) {
  81. if (bottomright > (SCREEN_WIDTH * 0.9) && bottomleft < (SCREEN_WIDTH * 0.1))
  82. {
  83. positivedirection = false;
  84. }
  85.  
  86. if (bottomright <(SCREEN_WIDTH/2) && bottomleft > (SCREEN_WIDTH/2))
  87. {
  88. positivedirection = true;
  89. }
  90.  
  91. if (positivedirection)
  92. {
  93. // interpolate on a vertex to make it looks like a quad becoming a triangle
  94. interpolation[2].position = sf::Vector2f(bottomright += 1, (SCREEN_HEIGHT * 0.9)); //bottom right 100 100
  95. interpolation[3].position = sf::Vector2f(bottomleft -=1 , (SCREEN_HEIGHT * 0.9));
  96. }
  97. else if (!positivedirection)
  98. {
  99. // interpolate on a vertex to make it looks like a quad becoming a triangle
  100. interpolation[2].position = sf::Vector2f(bottomright -= 1, (SCREEN_HEIGHT * 0.9)); //bottom right 100 100
  101. interpolation[3].position = sf::Vector2f(bottomleft += 1, (SCREEN_HEIGHT * 0.9));
  102. }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement