SFML и C++ Уроки \ Разработка игр › Форумы › SFML Graphics › Циклическая смена цвета › Ответ в теме: Циклическая смена цвета
Изи
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
#include <SFML/Graphics.hpp> using namespace sf; void main() { Clock clock; int i=0,t=0; float swichtime = 0; const Color colorArray[3] = { Color::Red, Color::Blue, Color::Green }; RenderWindow window(VideoMode(1024, 768), "My Window"); ConvexShape polygon[6]; polygon[0].setPointCount(3); polygon[0].setFillColor(Color::White); polygon[0].setPoint(0, Vector2f(300, 300)); polygon[0].setPoint(1, Vector2f(300, 0)); polygon[0].setPoint(2, Vector2f(0, 100)); polygon[0].setPosition(100, 50); polygon[1].setPointCount(3); polygon[1].setFillColor(Color::White); polygon[1].setPoint(0, Vector2f(300, 300)); polygon[1].setPoint(1, Vector2f(600, 100)); polygon[1].setPoint(2, Vector2f(300, 0)); polygon[1].setPosition(100, 50); polygon[2].setPointCount(3); polygon[2].setFillColor(Color::White); polygon[2].setPoint(0, Vector2f(300, 300)); polygon[2].setPoint(1, Vector2f(600, 100)); polygon[2].setPoint(2, Vector2f(600, 500)); polygon[2].setPosition(100, 50); polygon[3].setPointCount(3); polygon[3].setFillColor(Color::White); polygon[3].setPoint(0, Vector2f(300, 300)); polygon[3].setPoint(1, Vector2f(600, 500)); polygon[3].setPoint(2, Vector2f(300, 600)); polygon[3].setPosition(100, 50); polygon[4].setPointCount(3); polygon[4].setFillColor(Color::White); polygon[4].setPoint(0, Vector2f(300, 300)); polygon[4].setPoint(1, Vector2f(0, 500)); polygon[4].setPoint(2, Vector2f(300, 600)); polygon[4].setPosition(100, 50); polygon[5].setPointCount(3); polygon[5].setFillColor(Color::White); polygon[5].setPoint(0, Vector2f(300, 300)); polygon[5].setPoint(1, Vector2f(0, 100)); polygon[5].setPoint(2, Vector2f(0, 500)); polygon[5].setPosition(100, 50); while (window.isOpen()) { Event event; while (window.pollEvent(event)) { if (event.type == Event::Closed) window.close(); } if (swichtime == 0) { polygon[i].setFillColor(colorArray[t]); i++; } swichtime = clock.getElapsedTime().asSeconds(); if (swichtime>1){ clock.restart(); swichtime = 0; } if (i > 5){i = 0;t++;} if (t > 2) t = 0; window.clear(); for (int i = 0; i < 6; i++) { window.draw(polygon[i]); } window.display(); } } |