-
Notifications
You must be signed in to change notification settings - Fork 0
/
GOL.pde
115 lines (104 loc) · 2.52 KB
/
GOL.pde
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
3d Pressure Simulator
by Wilson Wang
*/
int noc = 25;
int[][][] Pnew = new int[noc][noc][noc]; // Pressure before Iteration
int[][][] Pold = new int[noc][noc][noc]; // Pressure after Iteration
boolean[][][] type = new boolean[noc][noc][noc]; // Cell Type (true| Soild; False| Air)
boolean m_isRunning = false; // Paused
boolean CameraLock = true; // Is Camera Locked
boolean isview2d = true; // Is simulation in 2d view
// Frame Number
int frame = 1;
//Settings
void settings()
{
size(600,600, P3D);
}
void setup()
{
frameRate(60);
lockCam(3); // set starting 3d view to pos 3
}
void draw()
{
if (m_isRunning == true) // if the game is not paused
{
frame++;
if(frame % 15 == 0) // update only every 15 frames
{
update();
frame = 0;
}
}
if(isview2d) { // is the view is 2d
view2D();
} else { // run 3d view code
render();
setCamera();
updateCamera();
moveCamera();
}
}
void calculateNextGeneration() // Calculate the Next Generation
{
for(int i = 0; i < noc; i++)
{
for(int j = 0; j < noc; j++)
{
for(int k = 0; k < noc; k++)
{
if(type[i][j][k] == false) // if it is air
spread(i,j,k); // Spread the Pressure of that Cube to those around it
if(Pnew[i][j][k] > 0) // if the Pressure is grater that 0
{
if(int(random(0,2)) == 1) // 50% chance of radiating a bit of pressure away
Pnew[i][j][k] -= 1;
}
if(Pnew[i][j][k] < 0) // if the pressure is less than 0
{
Pnew[i][j][k] = 0; // set the pressure back to 0
}
}
}
}
}
void update()
{
setPrevWorld(); // set the previous world
calculateNextGeneration(); // Run the Calculations
}
void render() // The Drawing part for 3d View
{
background(0,0,80);
noStroke();
for(int i = 0; i < noc; i++)
{
translate(30,-30*noc,0); // move next block down vertically
for(int j = 0; j < noc; j++)
{
translate(0,30,-30*noc); // move next block left horisontally
for(int k = 0; k < noc; k++)
{
translate(0,0,30); // move next block back
//air block
if(type[i][j][k] == false)
{
if(Pnew[i][j][k] > 0)
{
fill(255, Pnew[i][j][k],0,Pnew[i][j][k]); // adds transparency base on the pressure
pushMatrix();
box(28);
popMatrix();
}
} else { // Solid block
fill(0, 255,0);
pushMatrix();
box(28);
popMatrix();
}
}
}
}
}