-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
62 lines (53 loc) · 1.01 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
#include "particle.h"
#include <Processing>
#include <vector>
using namespace processing;
using namespace std;
std::vector<Particle *> particles;
void reset_particle(Particle *p)
{
float x = random(width);
float y = random(height);
float vx = random(-5, 5);
float vy = random(-5, 5);
float h = random(0, 255);
float s = random(0, 255);
color c(h, s, 255);
p->setColor(c);
p->setPosition(x, y);
p->setVelocity(vx, vy);
}
void mousePressed()
{
for (auto p : particles)
reset_particle(p);
}
void setup()
{
size(400, 300);
setFrameRate(60);
for (int i = 0; i < 100; i++)
{
Particle *p = new Particle(0, 0);
reset_particle(p);
particles.push_back(p);
}
}
void draw()
{
colorMode(RGB);
background(204);
colorMode(HSB);
for (auto p : particles)
{
p->boundary();
p->applyForce(gravity);
p->update();
p->show();
}
}
void leave()
{
for (auto p : particles)
delete p;
}