-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPolarParticle.cpp
51 lines (45 loc) · 1.16 KB
/
PolarParticle.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
/*
* Particle simulation program using the SDL library
* Based on examples by John Purcell's (from Cave of Programming)
*
* @author J. Alvarez
*/
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include "PolarParticle.hpp"
#include "Screen.hpp"
namespace ParticleSimulation {
PolarParticle::PolarParticle(int mode): m_phase(0), Particle(0, 0, 0, 0, mode) {
m_coord1 = 3.0 * rand() / RAND_MAX;
m_coord2 = 2 * M_PI * rand() / RAND_MAX;
switch (m_mode) {
case Mode::POLR_FLWR:
m_coord1Speed = -0.0015;
m_coord2Speed = 0.0001;
break;
case Mode::POLR_SPRL:
m_coord1Speed = -0.015;
m_coord2Speed = 0.01;
break;
default:
std::cout << "Polar mode" << m_mode << "not implemented!" << std::endl;
break;
}
}
void PolarParticle::update(int interval) {
m_phase += m_coord1Speed * interval;
m_coord2 += m_coord2Speed * interval;
switch (m_mode) {
case Mode::POLR_FLWR:
m_coord1 = 300 * sin(4 * m_coord2 + m_phase);
break;
case Mode::POLR_SPRL:
m_coord1 = (4 * m_coord2 + m_phase);
break;
default:
std::cout << "Polar mode" << m_mode << "not implemented!" << std::endl;
break;
}
}
} // namespace ParticleSimulation