-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
74 lines (59 loc) · 1.86 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
73
74
#include <cmath>
#include <thread>
#include <chrono>
#include <ctime>
#include <SFML/Graphics.hpp>
#include <ParticleSystem.hpp>
#include <FlowField.hpp>
int main()
{
// seed the rng
srand(time(0));
// some config variables
const int windowWidth = 640;
const int windowHeight = 640;
const unsigned int particlesCount = 6400;
const bool showParticles = true;
const bool showFlowfield = false;
const sf::Color backgroundColor = sf::Color::White;
const sf::Color flowfieldColor = sf::Color(0, 0, 0, 100);
const sf::Color particlesColor = sf::Color(0, 0, 0, showFlowfield ? 255 : 2);
// create particle system
ParticleSystem particles = ParticleSystem(particlesCount, particlesColor, 1, windowWidth, windowHeight, showParticles);
// create flow field
FlowField flowfield = FlowField(windowWidth, windowHeight, 10.f, flowfieldColor, showFlowfield);
// create window
sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "Smoke");
window.setVerticalSyncEnabled(true);
window.clear(backgroundColor);
// run the main loop
while (window.isOpen())
{
// handle events
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
{
window.clear(backgroundColor);
}
// process
particles.follow(flowfield.generate(), flowfield.getScale());
// draw
if (showFlowfield)
{
window.clear(backgroundColor);
window.draw(flowfield);
}
if (showParticles)
{
window.draw(particles);
}
window.display();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
return 0;
}