#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
using namespace sf;
int main() {
Clock zegar;
Time time;
RenderWindow okno(VideoMode(800, 600), "test");
const std::size_t numberOfRectangles = 21; // uses an extra rectangle for overlap
RectangleShape pasek[numberOfRectangles];
int siz = 600 / 40;
for (int i = 0; i < numberOfRectangles; i++) {
pasek[i].setSize(sf::Vector2f(6, siz));
pasek[i].setFillColor(sf::Color(255, 255, 255));
}
for (int i = 0; i < numberOfRectangles; i++) {
pasek[i].setPosition(0, siz * 2 * i);
}
int temp;
int speed = 100;
while (okno.isOpen()) {
// simple event loop
sf::Event event;
while (okno.pollEvent(event))
{
if (event.type == sf::Event::Closed)
okno.close();
}
time = zegar.restart();
for (int i = 0; i < numberOfRectangles; i++) {
pasek[i].move(sf::Vector2f(0, speed * time.asSeconds()));
if (pasek[i].getPosition().y > siz * ((numberOfRectangles - 1) * 2))
pasek[i].setPosition(0, pasek[i].getPosition().y - (siz * numberOfRectangles * 2) ); // moves y up by window's size plus a rectangle AND a space (if not set relatively, over time, the rectangles will lose their structure)
}
okno.clear();
temp = 800 * 0.4;
for (int i = 0; i < numberOfRectangles; i++) {
pasek[i].setPosition(temp, pasek[i].getPosition().y);
okno.draw(pasek[i]);
}
temp = 800 * 0.6;
for (int i = 0; i < numberOfRectangles; i++) {
pasek[i].setPosition(temp, pasek[i].getPosition().y);
okno.draw(pasek[i]);
}
okno.display();
}
}