you ***can create it from scratch but it's a horrible mess, because the table is so irregular.
I didn't even apply the correct colors...
It's using your 1st csv-file (optional)
- //
- final boolean DEBUG = true;
- final color black = color(#000000);
- final int gridx = 18; // number of cells in x direction
- final int gridy = 9; // number of cells in x direction
- final int sizeX=42; // size
- final int sizeY=42;
- Cell [][]coor = new Cell[gridy][gridx]; // grid
- //
- void setup () {
- size (900, 600);
- background (black);
- // frameRate(5);
- //
- String[] a = loadStrings ("periodic_table.csv");
- //println (a[3]);
- //
- // make grid
- int countInternal = 1;
- int atomic_number = 1;
- int addY=0;
- for (int j = 0; j<gridy; j++) {
- for (int i = 0; i<gridx; i++) {
- boolean exists=true;
- if (countInternal>1&&countInternal<18) exists=false;
- if (countInternal>20&&countInternal<31) exists=false;
- if (countInternal>38&&countInternal<49) exists=false;
- if (countInternal>=127&&countInternal<130) exists=false;
- if (countInternal>=145&&countInternal<148) exists=false;
- //
- // this is for the two little empty fields Lanthanides & Actinides
- boolean special = false; // normal field
- if (countInternal==93||countInternal==111) {
- special=true; // empty field
- atomic_number+=14;
- }
- //
- // the lower two lines for Lanthanides & Actinides
- if (j>=7) addY=22;
- //
- // if it is there read file "periodic_table.csv"
- String name="";
- if (a!=null) {
- name="";
- if (exists&&!special) {
- if (atomic_number<118) {
- String temp=a[atomic_number-1];
- String[] parts= split(temp, ',');
- println (temp);
- if (!temp.equals(""))
- name =parts[3];
- }
- }
- }
- //
- coor[j] [i] = new Cell ( i * (sizeX) + 72, j * (sizeY) + 42+addY,
- color (random (255), random (255), 0),
- atomic_number,
- exists,
- special,
- countInternal,
- name );
- //
- // if exists, increase atomic_number
- if (exists)
- atomic_number++;
- // this gets always increased
- countInternal++;
- }
- }
- }
- //
- void draw () {
- background (black);
- //
- // show grid
- for (int j = 0; j < gridy; j++) {
- for (int i = 0; i < gridx; i++) {
- coor[j] [i].display();
- }
- }
- textSize(12);
- text ("Lanthanides", 50+50, height-243+20);
- text ("Actinides", 50+50, height-200+20);
- // we assign one new color
- // int randoX = int (random(coor.length)); // rando = random number from array coor
- // int randoY = int (random(coor[1].length)); // rando = random number from array coor
- // coor [randoX][randoY].colCell= color (random (255), random (255), random (255));
- }
- //
- void keyPressed() {
- //
- }
- void mousePressed() {
- //
- }
- // =======================================================================
- class Cell {
- // one cell is one element
- int atomic_number;
- float mass_number;
- String name;
- String symbol;
- boolean exists=false;
- boolean special=false;
- float x;
- float y;
- float w=sizeX; //width/gridx-10;
- float h=sizeY; //height/gridy-10;
- color colCell;
- int countInternal;
- //
- Cell ( float x_, float y_,
- color c_, int countExternal_,
- boolean exist_, boolean special_,
- int countInternal_,
- String name_ ) {
- x=x_;
- y=y_;
- colCell=c_;
- atomic_number=countExternal_;
- exists=exist_ ;
- special=special_;
- countInternal=countInternal_;
- name=name_;
- }
- //
- void display () {
- if (exists) {
- fill(colCell);
- stroke(255);
- rect(x, y, w, h);
- fill(255);
- textSize(12);
- if (!special) {
- text(atomic_number, x+16, y+18);
- text(name, x+16, y+28);
- }
- if (DEBUG) {
- textSize(8);
- text(""+countInternal+"", x+12, y+34);
- }
- }
- }
- //
- } // class
- // =======================================================================