-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
97 lines (81 loc) · 1.64 KB
/
main.cpp
File metadata and controls
97 lines (81 loc) · 1.64 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#define OLC_PGE_APPLICATION
#include "include/olcPixelGameEngine.h"
#include "include/particle.h"
#include "include/trailmap.h"
#include "include/utils.h"
#include <cmath>
#include <cstdlib>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;
class Physarum : public olc::PixelGameEngine
{
public:
Physarum()
{
sAppName = "Physarum Mold Simulation";
}
public:
// GLOBAL VARIABLES
int pixel_width = 1;
int mold_number = 120;
int speed = 10;
TrailMap trailmap;
Particle molds[120];
bool isPause = false;
public:
bool OnUserCreate() override
{
// SPAWN ALL PARTICLES
for (int i = 0; i < mold_number; i++)
{
molds[i].x = ScreenWidth() / 2;
molds[i].y = ScreenHeight() / 2;
molds[i].rotation = i * 3;
molds[i].speed = speed;
molds[i].state = 1;
molds[i].trailmap = &trailmap;
molds[i].sensor_distance = 10;
molds[i].sensor_angle = 45;
molds[i].sensor_size = 4;
}
return true;
}
bool OnUserUpdate(float fElapsedTime) override
{
// IF UNPAUSED
if (isPause == false)
{
// CLEAR SCREEN EVERY FRAME
Clear({0, 0, 0});
// UPDATE PARTICLES
for (int i = 0; i < mold_number - 1; i++)
{
//molds[i].Sense(this);
molds[i].Rotate(this);
molds[i].Move(this);
molds[i].Deposit(this);
//molds[i].Draw(this);
}
// UPDATE TRAILMAP
trailmap.Update(this);
}
// PAUSE SIMULATION
if (GetKey(olc::Key::SPACE).bPressed)
{
if (isPause == false)
isPause = true;
else if (isPause == true)
isPause = false;
}
return true;
}
};
int main()
{
Physarum simulation;
if (simulation.Construct(1440, 1440, 2, 2))
simulation.Start();
return 0;
}