-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorld.pde
64 lines (64 loc) · 2.49 KB
/
World.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
class World {
private PVector origin;
private PVector dim;
float worldBorderWidth = 10;
Table periodicTable;
float electronOffset = 20;
Atom[] atoms;
World(PVector origin, PVector dim, int atomCount) {
this.origin = origin;
this.dim = new PVector(dim.x, dim.y);
println(this.dim);
this.periodicTable = loadTable("elements.csv", "header");
atoms = new Atom[atomCount];
for (int a = 0; a < atoms.length; a++) {
int electronCount = int(random(50, 90));
float x = random(this.origin.x + getAtomWidth(electronCount) + 10, this.dim.x - getAtomWidth(electronCount));
float y = random(this.origin.x + getAtomWidth(electronCount), this.dim.y - getAtomWidth(electronCount));
atoms[a] = new Atom(x, y, electronCount, 20, getAtomName(electronCount), electronOffset);
//println((a+1)+": "+atoms[a]);
}
}
void renderWorld() {
strokeWeight(worldBorderWidth);
stroke(255);
// Top
line(this.origin.x + (worldBorderWidth / 2), this.origin.y + (worldBorderWidth / 2), this.dim.x - (worldBorderWidth / 2), this.origin.y + (worldBorderWidth / 2));
// Bottom
line(this.origin.x + (worldBorderWidth / 2), this.dim.y - (worldBorderWidth / 2), this.dim.x - (worldBorderWidth / 2), this.dim.y - (worldBorderWidth / 2));
// Right
line(this.dim.x - (worldBorderWidth / 2), this.origin.y + (worldBorderWidth / 2), this.dim.x - (worldBorderWidth / 2), this.dim.y - (worldBorderWidth / 2));
// Left
line(this.origin.x + (worldBorderWidth / 2), this.origin.y + (worldBorderWidth / 2), this.origin.x + (worldBorderWidth / 2), this.dim.y - (worldBorderWidth / 2));
}
void renderAtoms() {
for (Atom atom : atoms)
atom.show();
}
void updateAtoms() {
for (Atom atom : atoms)
atom.update(this.dim.x - worldBorderWidth, this.dim.y - worldBorderWidth);
}
String getAtomName(int atomCount) {
for (TableRow elementRow : periodicTable.rows()) {
if (atomCount == elementRow.getInt("atomicNumber")) {
return elementRow.getString("symbol");
}
}
return "NULL";
}
Atom getRandomAtom(PVector dim) {
int electronCount = int(random(10, 50));
Atom atom = new Atom(random(dim.x), random(dim.y), electronCount, 20, getAtomName(electronCount), this.electronOffset);
return atom;
}
float getAtomWidth(int electronCount) {
int n = 1;
println("Electron count: " + electronCount);
while (electronCount >= 2 * n * n) {
electronCount -= 2 * n * n;
n++;
}
return 2 * n * n;
}
}