/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.ZsKItO7KO6A/rev.7611
*
* authors:
* Benjamin Y
* Scienceby
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
// Pressing Control-R will render this sketch.
int i = 0;
int rad = 11;
int centXY = 200;
float[] ElAng = {1.09*2, 3.05*2, 2.78*2, 1.93*2, 1.69*2, 2.03*2, 0.35*2, 3.11*2, 2.47*2, 2.96*2, 2.88*2, 2.14*2, 0.24*2, 1.42*2, 2.32*2, 2.95*2, 0.86*2, 3.13*2, 0.23*2, 2.53*2};
float[] ElVel = {0.4, 0.4, 0.22, 0.22, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.11, 0.11, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05};
int[] ElRad = {70, 70, 90, 90, 100, 100, 100, 100, 100, 100, 130, 130, 140, 140, 140, 140, 140, 140, 190, 190};
String[] ElName = {'1s', '1s', '2s', '2s', '2p', '2p', '2p', '2p', '2p', '2p', '3s', '3s', '3p', '3p', '3p', '3p', '3p', '3p', '4s', '4s', '3d', '3d', '3d', '3d', '3d', '3d', '3d', '3d', '3d', '3d', '4p', '4p', '4p', '4p', '4p', '4p', '5s', '5s', '4d', '4d', '4d', '4d', '4d', '4d', '4d', '4d', '4d', '4d', '5p', '5p', '5p', '5p', '5p', '5p', '6s', '6s'};
int electrons = 20;
int hl = 0;
int speed = 0.2;
int runs = 0;
int A = 40;
boolean mouseTrail = false;
String[] HLives = {'35 ns'/*34*/, '25.7 ms', '102 ms', '181.1 ms', '440 ms', '859.6 ms', 'Stable', '102000 y', 'Stable', 'Stable', 'Stable', '162.67 d', 'Stable', '4.536 d', 'Stable', '8.718 min', '13.9 s', '10.0 s', '4.6 s', '90 ms', '50 ms', '30 ms', '10 ms', '5 ms'};
String[] DecayM = {'p', 'β+', 'β+, p', 'β+, p', 'β+', 'β+', 'N/A', 'EC', 'N/A', 'N/A', 'N/A', 'β-', 'N/A', 'β-', 'N/A', 'β-', 'β-', 'β-', 'β-', 'β-', 'β-', 'β-', 'β-', 'β-'};
void setup() { // this is run once.
// set the background color
background(255);
// canvas size (Variable aren't evaluated. Integers only, please.)
size(450, 650);
// smooth edges
smooth();
// limit the number of frames per second
frameRate(10);
// set the width of the line.
strokeWeight(4);
}
//void mouseWheel (
void draw() { // this is run repeatedly.
runs += 1;
background(255);
fill(0, 0, 255, 204);
text(runs, 29, 30);
//text(mouseWheel(), height-160, 24);
fill(255);
text('Ca Z: 20 A: 40', centXY-10, centXY+7);
noFill();
stroke(0, 0, 255, 204);
ellipse(centXY, centXY, 70*2, 70*2);
ellipse(centXY, centXY, 90*2, 90*2);
ellipse(centXY, centXY, 100*2, 100*2);
ellipse(centXY, centXY, 130*2, 130*2);
ellipse(centXY, centXY, 140*2, 140*2);
ellipse(centXY, centXY, 190*2, 190*2);
fill(0, 0, 255, 204);
text('X: '+((mouseX - centXY)), 6, 355);
text('Y: '+((mouseY - centXY)), 40, 355);
// PERIODIC TABLE
fill(0, 0, 255, 102);
noStroke();
rect(24, 415, 10, 70);
rect(34, 425, 10, 60);
rect(44, 465, 140, 20);
rect(184, 445, 10, 40);
rect(194, 445, 90, 40);
rect(284, 425, 60, 60);
rect(334, 415, 10, 10);
fill(153);
text('s', 24, 395);
text('s', 334, 395);
text('f', 124, 445);
text('d', 234, 425);
text('p', 304, 405);
stroke(153);
noFill();
strokeWeight(1);
rect(24, 415, 20, 70);
rect(334, 415, 10, 10);
rect(44, 465, 140, 20);
rect(184, 445, 100, 40);
rect(284, 425, 60, 60);
strokeWeight(4);
noFill();
stroke(0);
if (mouseX < 44 && mouseX > 24 && mouseY < 485 && mouseY > 415) {
rect(24, 415, 20, 70);
rect(334, 415, 10, 10);
fill(0);
text('s', 24, 395);
text('s', 334, 395);
}
if (mouseX < 344 && mouseX > 334 && mouseY < 425 && mouseY > 415) {
rect(24, 415, 20, 70);
rect(334, 415, 10, 10);
fill(0);
text('s', 24, 395);
text('s', 334, 395);
}
if (mouseX < 184 && mouseX > 44 && mouseY < 485 && mouseY > 465) {
rect(44, 465, 140, 20);
fill(0);
text('f', 124, 445);
}
if (mouseX < 284 && mouseX > 184 && mouseY < 485 && mouseY > 445) {
rect(184, 445, 100, 40);
fill(0);
text('d', 234, 425);
}
if (mouseX < 344 && mouseX > 284 && mouseY < 485 && mouseY > 425) {
rect(284, 425, 60, 60);
fill(0);
text('p', 304, 405);
}
fill(0, 0, 255, 51);
strokeWeight(1);
stroke(0, 0, 0, 153);
rect(34, 425, 10, 60);
fill(0, 0, 255, 204);
strokeWeight(1);
stroke(0, 0, 0);
rect(34, 445, 10, 10);
// CaCO3
/*noStroke();
fill(0, 255, 0);
ellipse(250, 450, 30, 30);
fill(0);
ellipse(300, 450, 20, 20);
fill(255, 0, 0);
ellipse(340, 450, 18, 18);
ellipse(320, 430, 18, 18);
ellipse(320, 470, 18, 18);
fill(0);
line(250, 450, 340, 450);*/
fill(0);
text('Ca-'+A, centXY-20, centXY+47);
text(HLives[A-34], centXY-20, centXY+60);
text(DecayM[A-34], centXY-20, centXY-47);
strokeWeight(4);
fill(0, 0, 255, 51);
stroke(0, 0, 255, 51);
line(width-49, height-35+16, width-49, height-630);
if(mouseTrail) {
line(pmouseX, pmouseY, mouseX, mouseY);
}
stroke(0, 0, 255, 204);
rect(510, height-500, 25, 500);
int j = 0;
for(int i = 35;i < 630;i=i+16) {
if (j < electrons) {
fill(0, 0, 255, 51);
} else {
noFill();
}
rect(width-40, height-i, 25, 16);
if (j < electrons) {
fill(0, 0, 255, 204);
text(ElName[j], width-35, height-i+11);
if ((mouseX > width-40-9) && (mouseX < width-40 + 25) && (mouseY > height-i) && (mouseY < height-i + 16)) {
int ElX = cos(ElAng[j])* ElRad[j];
int ElY = sin(ElAng[j])* ElRad[j];
fill(0, 0, 255, 51);
ellipse(ElX + centXY, ElY + centXY, 24, 24);
noStroke();
rect(width-49, height-i, 9, 16);
fill(0, 0, 255, 204);
stroke(0, 0, 255, 204);
line(width-49, height-i, width-49, height-i+16);
stroke(0, 0, 255, 25);
line(width-49, height-35+16, width-49, height-i);
stroke(0, 0, 255, 25);
noFill();
ellipse(centXY, centXY, ElRad[j]*2-10, ElRad[j]*2-10);
ellipse(centXY, centXY, ElRad[j]*2+10, ElRad[j]*2+10);
stroke(0, 0, 255, 102);
}
} else {
fill(0, 0, 255, 204);
text(ElName[j], width-35, height-i+11);
}
j += 1;
}
fill(0, 0, 255, 25.5);
noStroke();
switch( hl ) {
case 0:
ellipse(centXY, centXY, 145*2, 145*2);
break;
case 1:
ellipse(centXY, centXY, 160*2, 160*2);
ellipse(centXY, centXY, 120*2, 120*2);
break;
case 2:
ellipse(centXY, centXY, 180*2, 180*2);
ellipse(centXY, centXY, 120*2, 120*2);
ellipse(centXY, centXY, 80*2, 80*2);
ellipse(centXY, centXY, 60*2, 60*2);
break;
case 3:
ellipse(centXY, centXY, 35*2, 35*2);
break;
}
//text("# "+String(hl+1), centXY+100, height-70);
// set the color
stroke(0, 0, 255, 204);
fill(0, 0, 255, 204);
noFill();
rect(1, 1, width-2, height-5);
stroke(0, 0, 255, 102);
rect(3, 3, width-6, height-11);
stroke(0, 0, 255, 51);
rect(5, 5, width-10, height-15);
stroke(0, 0, 255, 26);
rect(8, 8, width-16, height-21);
stroke(0, 0, 255, 13);
rect(11, 11, width-22, height-27);
stroke(0, 0, 255, 7);
rect(16, 16, width-32, height-37);
stroke(0, 0, 255, 204);
fill(0, 0, 255, 204);
text("Hover on bottom to see auth info", 12, height-150);
text("Press I to change between Calcium and Calcium Ion", 12, height-50);
text("Press H to change between highliting formats", 12, height-70);
text("Press U to increase speed", 12, height-90);
text("Press J to decrease speed", 12, height-110);
text("Press Y to toggle mouse trail", 12, height-130);
if (electrons == 20) {
text("Ca ( 1s2 2s2 2p6 3s2 3p6 4s2 )", 12, height-30);
} else {
text("Ca 2+ ( 1s2 2s2 2p6 3s2 3p6 )", 12, height-30);
}
if (mouseY > height-29) {
// whiteout
noStroke();
fill(255);
rect(12, height-125, width-74, 130-50);
fill(0, 0, 255, 51);
rect(12, height-125, width-74, 130-50);
stroke(0, 0, 255, 204);
fill(0, 0, 255, 204);
text("16:39:12 GMT-8:00", 12, height-50);
text("Last edited Feb 8, 2016", 12, height-70);
text("5247 edits", 12, height-90);
text("By Benjamin Y", 12, height-110);
}
text("1s", centXY, centXY-60);
text("2s 2p", centXY, centXY-80);
text("3s 3p", centXY, centXY-120);
text("4s", centXY, centXY-180);
textSize(20);
ellipse(200, 200, rad*5, rad*5);
//1s
ElX = centXY;
ElY = centXY;
double dist = sqrt(sq(ElX-mouseX)+sq(ElY-mouseY));
if (dist < 35) {
fill(0, 0, 255, 51);
ellipse(ElX, ElY, 70, 70);
fill(0, 0, 255, 204);
}
for (int i = 0; i < electrons; i += 1) {
int ElX = cos(ElAng[i])* ElRad[i];
int ElY = sin(ElAng[i])* ElRad[i];
double dist = sqrt(sq(ElX-mouseX)+sq(ElY-mouseY));
ellipse(ElX + centXY, ElY+ centXY, rad, rad)
ElAng[i]+=ElVel[i]*speed+random(-0.004, 0.004);
if ((mouseX > ElX + centXY - 12) && (mouseX < ElX + centXY + 12) && (mouseY > ElY + centXY - 12) && (mouseY < ElY + centXY + 12)) {
fill(0, 0, 255, 51);
ellipse(ElX + centXY, ElY + centXY, 24, 24);
fill(0, 0, 255, 204);
}
}
if (keyPressed == true) {
if (key == 'i' || key == 'I') {
if (electrons == 20) {
electrons = 18;
} else {
electrons = 20;
}
} else if (key == 'h' || key == 'H') {
switch (hl) {
case 0:
hl = 1;
break;
case 1:
hl = 2;
break;
case 2:
hl = 3;
break;
case 3:
hl = 0;
break;
}
} else if (key == 'u' || key == 'U') {
speed += 0.1;
} else if (key == 'j' || key == 'J') {
speed -= 0.1;
} else if (key == 'y' || key == 'Y') {
mouseTrail = !mouseTrail;
} else if (key == 'l' || key == 'L') {
if (A > 34) {
A -= 1;
}
} else if (key == 'o' || key == 'O') {
if (A < 57) {
A += 1;
}
} else if (key == 'k' || key == 'K') {
A = 40;
}
}
//
fill(0, 0, 255, 60);
stroke(0, 0, 255, 60);
ellipse(mouseX, mouseY, 5, 5);
}