/**************************************************************** // 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 minx = 0; maxx = 1920; miny = 0; maxy = 1150; // Custom screen size color = 0x22ccee; 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(); nprot p[pqty]; // Get an array of neutrons for(x = 0; x < pqty; x++){ // Make pqty neutrons p[x].setmass(); } pqty = 10; // 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); for(x = 0; x < pqty; x++){ p[x].move(); if(c1.vec == 1) p[x].showvec(); for(y = 0; y < pqty; y++){ if(x > y) p[y].bump(p[x], c1); } } SDL_UpdateRect(screen, minx, miny, maxx, maxy); if(c1.trigger == 1){ SDL_Delay(2500); c1.trigger = 0; } if(c == 'q') break; if(c == 'f') p[1].vt += 10; 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') c1.setview(); if(c == 'p') c1.setvec(); if(c == 'g'){ for(x = 0; x < pqty; x++){ if(p[x].z < 1.5) p[x].z += .05; } } if(c == 's'){ for(x = 0; x < pqty; x++){ if(p[x].z > .06) p[x].z -= .05; else p[x].z = .05; } } SDL_Delay(10); } SDL_Quit(); }