-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticle.h
53 lines (46 loc) · 1.04 KB
/
particle.h
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
#ifndef PARTICLE_H
#define PARTICLE_H
#include <Processing>
using namespace processing;
const float gravity = -0.098;
class Particle
{
public:
Particle(float x, float y) : r(8), vx(0), vy(0), x(x), y(y) {}
void setColor(const color &c_) { c = c_; }
void setPosition(float x_, float y_) { x = x_; y = y_; }
void setVelocity(float vx_, float vy_) { vx = vx_; vy = vy_; }
void applyForce(float fy) { vy -= fy; }
void update() { x += vx; y += vy; }
void show() {
fill(c);
ellipse(x, y, 2 * r, 2 * r);
}
void boundary() {
if (x < r) {
x = r;
vx *= -0.9;
}
if (x > width - r) {
x = width - r;
vx *= -0.9;
}
if (y < r) {
y = r;
vy *= -1.0;
}
if (y > height - r) {
y = height - r;
vy *= -0.8;
}
if (y == height -r)
vx *= 0.9;
}
color c;
float r;
float vx;
float vy;
float x;
float y;
};
#endif // PARTICLE_H