/**************************************************************** // 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" struct grid { int hash; // distance between grid lines int titx; // x location of the tit int tity; // y location of the tit int wavelength; // distance between peaks int xx; // left-right grid starting point int yy; // up-down grid starting point int colorx; int colory; int colorbk; int tog; void sweet(int x, int y, int th){ th *= 2; putpixel(maxx - x + 1, y - th, colory); // 1 = x + 1, y putpixel(maxx - x + 1, y + 1 - th, colory); // 2 = x + 1, y + 1 putpixel(maxx - x, y + 1 - th, colory); // 3 = x, y + 1 putpixel(maxx - x - 1, y + 1 - th, colory); // 4 = x - 1, y + 1 putpixel(maxx - x - 1, y - th, colory); // 5 = x - 1, y putpixel(maxx - x - 1, y - 1 - th, colory); // 6 = x - 1, y - 1 putpixel(maxx - x, y - 1 - th, colory); // 7 = x, y - 1 putpixel(maxx - x + 1, y - 1 - th, colory); // 8 = x + 1, y - 1 putpixel(maxx - x + 1, maxy - y - th, colory); putpixel(maxx - x + 1, maxy - y + 1 - th, colory); putpixel(maxx - x, maxy - y + 1 - th, colory); putpixel(maxx - x - 1, maxy - y + 1 - th, colory); putpixel(maxx - x - 1, maxy - y - th, colory); putpixel(maxx - x - 1, maxy - y - 1 - th, colory); putpixel(maxx - x, maxy - y - 1 - th, colory); putpixel(maxx - x + 1, maxy - y - 1 - th, colory); putpixel(x + 1, y - th, colory); putpixel(x + 1, y + 1 - th, colory); putpixel(x, y + 1 - th, colory); putpixel(x - 1, y + 1 - th, colory); putpixel(x - 1, y - th, colory); putpixel(x - 1, y - 1 - th, colory); putpixel(x, y - 1 - th, colory); putpixel(x + 1, y - 1 - th, colory); putpixel(x + 1, maxy - y - th, colory); putpixel(x + 1, maxy - y + 1 - th, colory); putpixel(x, maxy - y + 1 - th, colory); putpixel(x - 1, maxy - y + 1 - th, colory); putpixel(x - 1, maxy - y - th, colory); putpixel(x - 1, maxy - y - 1 - th, colory); putpixel(x, maxy - y - 1 - th, colory); putpixel(x + 1, maxy - y - 1 - th, colory); } void mkgrid(){ double x, y, xxx, th = 0; double xxxx = xx; ColorFill(colorbk, maxx, maxy); for(xxx = 0; xxx < maxx; xxx ++){ x = xxxx; y = yy; // th is virtical offset for tit while(y < maxy){ x += 1; if(tog == 1){ y += 1; tog = 0; } else tog = 1; double dx = titx - x; double dy = tity - y; double dif = sqrt(dx * dx + dy * dy); dif /= 40; if(dif < .2) dif = .2; th = 20 / (dif); putpixel(maxx - x, y - th, colory); putpixel(maxx - x, maxy - y - th, colory); putpixel(x, y - th, colory); putpixel(x, maxy - y - th, colory); if(th > 15){ // Enhance sweet spot sweet(x, y, th); } } xxxx += hash; } } void reset(){ hash = 15; titx = maxx / 2; tity = maxy / 2; xx = 0; yy = 0; tog = 0; colorx = 0xff0000; colory = 0xffffff; colorbk = 0x000000; wavelength = 500; } }; int main(int argc, char **argv) { // Default screen size and color is in neutronlib.h minx = 0; maxx = 1920; miny = 0; maxy = 960; // Custom screen size redefined char c = 0; int x, y, updt = 10; grid grid0; 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); grid0.reset(); SDL_UpdateRect(screen, minx, miny, maxx, maxy); while(1){ ColorFill(color, maxx, maxy); c = keystroke(); grid0.mkgrid(); SDL_UpdateRect(screen, minx, miny, maxx, maxy); if(c == 'q') break; if(c == 'd') SDL_Delay(5000); if(c == 'c') grid0.colorbk += 0xff; SDL_Delay(1); if(grid0.titx < maxx) grid0.titx += 1; else grid0.reset(); } SDL_Quit(); }