/**************************************************************** // Square of the Shells Neutron Model // Neutron Model according to the Square of Shells Rule. // Mass is in units of electron masses // Rule: Take Shell One mass as equal to Neutron - Proton mass. // Shell two mass is then the square of Shell one mass. // Shell three mass is the square of shell two mass. // Shell four mass is equal to the square of shell three mass. // The sum of shells one two and three is Proton mass. // The sum of all four shells is Neutron Mass. // Compile and run from the command line with: // // g++ prot.cpp -l SDL // ./a.out // // Requires the SDL library and neutronlib.h /****************************************************************/ #include #include #include #include #include #include "neutronlib.h" int main(int argc, char **argv) { // Default screen size and color is in neutronlib.h double mu = 0; minx = 0; maxx = 1920; miny = 0; maxy = 1100; // Custom screen size color = 0x888875; char c = 0; int pmax = 100; int x, y, pqty = pmax; time_t seconds; seconds = time (NULL); unsigned int sec = seconds; srand(sec); control c1; c1.reset(); abc typ; typ.init(10, 10, 1); nprot p[pqty]; // Get an array of neutrons for(x = 0; x < pqty; x++){ // Make pqty neutrons p[x].setmass(); mu += p[x].p; p[x].id = x; } pqty = 2; // Only show this many neutrons if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1)) { printf("Could not initialize SDL: %s.\n", SDL_GetError()); exit(-1); } init_screen(maxx, maxy); ColorFill(color, maxx, maxy); SDL_UpdateRect(screen, minx, miny, maxx, maxy); while(1){ ColorFill(color, maxx, maxy); c = keystroke(); if(c == 'w') SDL_Delay(5000); mu = 0; for(x = 0; x < pqty; x++){ p[x].move(); mu += p[x].p; if(c1.vec == 1) p[x].showvec(); if(c1.twovec == 1){ p[0].showvec(); p[pqty - 1].showvec(); } for(y = x + 1; y < pqty; y++){ p[x].bump(p[y], c1); } } for(x = 5; x < 10; x ++){ linexy(40, x, 40 + mu * .001, x, 0xffff00); } SDL_UpdateRect(screen, minx, miny, maxx, maxy); if(c1.trigger == 1){ SDL_Delay(5000); c1.trigger = 0; } if(c == 'q') break; if(c == 'f'){ p[1].vt += 10; p[0].vt += 10; p[2].vt += 10; } if(c == 'o'){ p[1].vt = 0; p[0].vt = 0; p[2].vt = 0; } if(c == '0'){ if(pqty > 1) pqty --; } if(c == '1'){ if(pqty < pmax) pqty ++; } if(c == 'r') c1.reset(); if(c == 'l') c1.setlines(); if(c == 'v'){ color = rand() %0xffffff; } if(c == 'p') c1.setvec(); if(c == 'a') c1.settwovec(); if(c == 'e') p[1].addelec(); if(c == 'd') SDL_Delay(5000); if(c == 'g'){ for(x = 0; x < pqty; x++){ if(p[x].z < 1.5) p[x].z += .01; } } if(c == 's'){ for(x = 0; x < pqty; x++){ if(p[x].z > .02) p[x].z -= .01; else p[x].z = .02; } } SDL_Delay(20); } SDL_Quit(); }