Repository navigation
Expand file tree
/
Copy pathManager.java
More file actions
executable file
·100 lines (82 loc) · 2.26 KB
/
Copy pathManager.java
File metadata and controls
executable file
·100 lines (82 loc) · 2.26 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
98
99
100
package com.github.marioariasga.cellsimulator;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import com.github.marioariasga.cellsimulator.environment.Environment;
import com.github.marioariasga.cellsimulator.environment.EnvironmentGradient;
public class Manager {
private static Manager inst = null;
public static Manager getInstance() {
if(inst==null) {
inst = new Manager();
}
return inst;
}
List<Cell> cels = new ArrayList<Cell>(Constants.NUM_CELLS);
Environment env;
long time=1;
public Manager() {
env = new EnvironmentGradient();
// env = new EnvironmentStep();
// env = new EnvironmentGauss();
// env = new EnvironmentConstant();
resetAll();
}
void reset() {
time=1;
for(Cell c : cels) {
c.reset();
}
}
void resetAll() {
time=1;
cels.clear();
for(int i=0;i<Constants.NUM_CELLS;i++) {
double x = Util.getRandomUniform(0.0, env.getWidth());
double y = Util.getRandomUniform(0.0, env.getHeight());
double angle = Util.getRandomUniform(0.0, Math.PI*2);
double speed = Util.getRandomUniform(Constants.MIN_SPEED, Constants.MAX_SPEED);
Cell c = new CellulaDisc(x,y,angle,speed);
c.setColor(Color.red);
cels.add(c);
}
/*
for(int i=Constants.NUM_PARTICLES/2;i<Constants.NUM_PARTICLES;i++) {
double x = Util.getRandomUniform(0, env.getWidth());
double y = Util.getRandomUniform(0.0, env.getHeight());
double angle = Util.getRandomUniform(0.0, Math.PI*2);
double speed = Util.getRandomUniform(Constants.MIN_SPEED, Constants.MAX_SPEED);
Cellula c = new CellulaDisc(x,y,angle,speed);
c.setColor(Color.green);
cels.add(c);
}*/
}
public void performIteration() {
time++;
for(Cell c : getCels()) {
c.move(getEnv());
}
}
public void performIterations(int n) {
if(n<0) return;
for(int i=0;i<n;i++) {
performIteration();
}
}
public List<Cell> getCels() {
return cels;
}
public void setEnv(Environment env) {
this.env = env;
}
public Environment getEnv() {
return env;
}
public long getTime() {
return time;
}
public static void main(String[] args) {
Manager.getInstance();
new Visualizer().createWindow();
}
}