-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
72 lines (60 loc) · 1.41 KB
/
main.cpp
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
#include "SFML/Graphics.hpp"
#include <iostream>
#define WIDTH 400
#define HEIGHT 300
void swap(sf::RectangleShape &a, sf::RectangleShape &b)
{
float temp = a.getSize().y;
a.setSize(sf::Vector2f(1, b.getSize().y));
b.setSize(sf::Vector2f(1, temp));
}
int main()
{
srand(time(0));
sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "BubbleSort");
sf::RectangleShape Lines[WIDTH / 2];
// window.setFramerateLimit(480);
float x = 0, y = 0;
bool flag = true;
for (auto &shape : Lines)
{
y = -(rand() % (290) + 2);
shape.setSize(sf::Vector2f(1, y));
shape.setPosition(x, HEIGHT);
x += 2;
}
int i = 0;
int j = 0;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
if (Lines[j].getSize().y < Lines[j + 1].getSize().y)
{
swap(Lines[j], Lines[j+1]);
}
for (int i = 0; i < WIDTH / 2; i++)
{
window.draw(Lines[i]);
}
if (i < WIDTH / 2 - 1)
{
j++;
if (j >= WIDTH / 2 - i -1 )
{
j = 0;
i++;
}
}
else
{
window.close();
}
window.display();
}
}