-
Notifications
You must be signed in to change notification settings - Fork 0
/
Atom.pde
78 lines (78 loc) · 2.36 KB
/
Atom.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
import java.util.*;
class Atom {
Electron[] electrons;
PVector pos;
PVector vel;
String atomTag;
float atomSize = 100;
float electronSize = 0;
float electronOffset;
ArrayList<Integer> shell;
Atom(float x, float y, int electronCount, int electronSize, String atomTag, float electronOffset) {
this.pos = new PVector(x, y);
this.vel = new PVector(random(-1, 1), random(-1, 1));
this.atomTag = atomTag;
this.electrons = new Electron[electronCount];
this.electronSize = electronSize;
this.electronOffset = electronOffset;
this.shell = new ArrayList();
// calculating arrangement
int n = 1;
println("Electron count: " + electronCount);
while (electronCount >= 2 * n * n) {
shell.add(2 * n * n);
electronCount -= 2 * n * n;
n++;
}
if (electronCount !=0)
shell.add(electronCount);
// initializing the electrons
int e = 0;
for (int a = 0; a < shell.size(); a++) {
int eNum = shell.get(a);
float angleOffset = 360 / eNum;
for (int b = 0; b < eNum; b++) {
electrons[e] = new Electron(this.pos.x, this.pos.y, angleOffset * b, this.electronSize, this.electronOffset * (a + 1));
println(electrons[e]);
e++;
}
}
}
void show() {
showParticles();
// Element name
fill(255);
textAlign(CENTER);
textSize(30);
text(this.electrons.length, this.pos.x, this.pos.y + 20);
text(this.atomTag, this.pos.x, this.pos.y - 5);
}
void showParticles() {
for (Electron electron : electrons) {
stroke(255);
electron.show();
electron.update(this.pos.x, this.pos.y);
}
}
void showShells() {
for (int a = shell.size(); a >= 1; a--) {
float shellOffset = this.electronOffset * a * 2;
fill(background, background);
stroke(255);
circle(this.pos.x, this.pos.y, shellOffset);
}
}
void update(float worldWidth, float worldHeight) {
this.pos.add(vel);
float outterBounding = this.shell.size() * electronOffset;
// Bounding
if (this.pos.x - outterBounding <= 0 || this.pos.x + outterBounding >= worldWidth)
this.vel.x *= -1;
if (this.pos.y - outterBounding <= 0 || this.pos.y + outterBounding >= worldHeight)
this.vel.y *= -1;
}
@Override
String toString() {
return "Atom{"+this.pos.x+", "+this.pos.y+",\nElectrons: "+Arrays.toString(this.electrons)+"}";
}
}