Advertisement
DrNuget

Untitled

Jun 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2.  
  3. class Window {
  4. public:
  5.     Window();
  6.     void run();
  7.     static int r, g, b;
  8. private:
  9.     void update();
  10.     void processEvents();
  11.     void render();
  12. private:
  13.     sf::RenderWindow window;
  14.     sf::Font font;
  15.     sf::Text text;
  16. };
  17.  
  18. Window::Window()
  19. : window(sf::VideoMode(640, 480), "Meme, haha xDDDD")
  20. , font()
  21. , text("Get On My Level", font) {
  22.     font.loadFromFile("arial.ttf");
  23.     text.setCharacterSize(50);
  24.     text.setColor(sf::Color(0, 0, 0));
  25. }
  26.  
  27. void Window::processEvents() {
  28.     sf::Event event;
  29.     while(window.pollEvent(event)) {
  30.         if (event.type==sf::Event::Closed)
  31.             window.close();
  32.     }
  33. }
  34.  
  35. void Window::run() {
  36.     while(window.isOpen()) {
  37.         processEvents();
  38.         update();
  39.         render();
  40.     }
  41. }
  42.  
  43. void Window::update() {
  44.     for (;r!=255&&g==0;r++)
  45.         text.setColor(sf::Color(r, g, b));
  46.     for (;g!=255&&b==0;g++)
  47.         text.setColor(sf::Color(r, g, b));
  48.     for (;r!=0&&g==255;r--)
  49.         text.setColor(sf::Color(r, g, b));
  50.     for (;b!=255&&g==255;b++)
  51.         text.setColor(sf::Color(r, g, b));
  52.     for (;g!=0&&b==255;g--)
  53.         text.setColor(sf::Color(r, g, b));
  54. }
  55.  
  56. void Window::render() {
  57.     window.clear();
  58.     window.draw(text);
  59.     window.display();
  60. }
  61.  
  62. int Window::r=0, Window::g=0, Window::b=0;
  63.  
  64. int main() {
  65.     Window win;
  66.     win.run();
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement