-
Notifications
You must be signed in to change notification settings - Fork 0
/
Atom.pde
156 lines (131 loc) · 3.93 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
Atoms
Alan Ball
*/
class Atom{
int X,Y,nX,nY,atomicNumber,radius,delay;
String atomicName = [];
int valenceNumber = [];
Atom(int tX,int tY,int tatomicNumber){
X = tX;
Y = tY;
nX = X;
nY = Y;
atomicNumber = tatomicNumber;
radius = 30;
delay = 50;
atomicName[1] = "H";
atomicName[2] = "He";
atomicName[3] = "Li";
atomicName[4] = "Be";
atomicName[5] = "B";
atomicName[6] = "C";
atomicName[7] = "N";
atomicName[8] = "O";
atomicName[9] = "F";
atomicName[10] = "Ne";
atomicName[11] = "Na";
atomicName[12] = "Mg";
atomicName[13] = "Al";
atomicName[14] = "Si";
atomicName[15] = "P";
atomicName[16] = "S";
atomicName[17] = "Cl";
atomicName[18] = "Ar";
atomicName[19] = "K";
atomicName[20] = "Ca";
atomicName[21] = "Sc";
atomicName[22] = "Ti";
atomicName[23] = "V";
atomicName[24] = "Cr";
atomicName[25] = "Mn";
atomicName[26] = "Fe";
atomicName[27] = "Co";
atomicName[28] = "Ni";
atomicName[29] = "Cu";
atomicName[30] = "Zn";
valenceNumber[1] = 1;
valenceNumber[2] = 2;
valenceNumber[3] = 1;
valenceNumber[4] = 2;
valenceNumber[5] = 3;
valenceNumber[6] = 4;
valenceNumber[7] = 5;
valenceNumber[8] = 6;
valenceNumber[9] = 7;
valenceNumber[10] = 8;
valenceNumber[11] = 1;
valenceNumber[12] = 2;
valenceNumber[13] = 3;
valenceNumber[14] = 4;
valenceNumber[15] = 5;
valenceNumber[16] = 6;
valenceNumber[17] = 7;
valenceNumber[18] = 8;
valenceNumber[19] = 1;
valenceNumber[20] = 2;
valenceNumber[21] = 3;
valenceNumber[22] = 4;
valenceNumber[23] = 5;
valenceNumber[24] = 6;
valenceNumber[25] = 7;
valenceNumber[26] = 8;
valenceNumber[27] = 8;
valenceNumber[28] = 8;
valenceNumber[29] = 1;
valenceNumber[30] = 1;
}
void moveAtom(){
nX = int(random(600));
nY = int(random(600));
// Track circle to new destination
X+=(nX-X)/delay;
Y+=(nY-Y)/delay;
}
void drawAtom(){
radius = radius + sin( frameCount / 4 );
int delay = 20;
int valenceElectrons;
fill(255);
stroke(120,60);
ellipse(X,Y,80,80);
// black
fill(0);
// white
stroke(255 ,120);
ellipse(X,Y,radius,radius);
valenceElectrons = valenceNumber[atomicNumber];
for(i = 0; i < valenceElectrons; i++){
drawElectron(X,Y,(i+1)*1.8, 40);
}
PFont font;
font = loadFont("FFScala-32.vlw");
textFont(font);
fill(255);
text(atomicName[atomicNumber], X-5,Y+5);
fill(120);
text(valenceElectrons.toString(),X+15,Y+20);
}
}
void drawElectron(int X,int Y,float offset, int radius){
float m = (millis()/2000)*offset;
eX = sin(m) * (radius ) + X;
eY = cos(m) * (radius ) + Y;
ellipse(eX,eY, 6, 6);
}
Atom atom;
// Setup the Processing Canvas
void setup(){
size( 600, 600 );
strokeWeight( 5 );
frameRate( 15 );
randomSeed(millis());
atom = new Atom(int(random(0,600)),int(random(0,600)),int(random(0,30)));
}
// Main draw loop
void draw(){
//white
background( 255 );
atom.drawAtom();
atom.moveAtom();
}