//+-------------------------------------------------------------------------+ //+ Program STARSC.C - October 8, 1994 + //+ + //+ By Ramiro Perez (Panama), rperez@ns.pa (Original program in Turbo BASIC)+ //+ and Fausto A. A. Barbuto (Brazil), BJ06@C53000.PETROBRAS.ANRJ.BR (Turbo + //+ BASIC to Borland C implementation and new formulations). + //+ + //+ Plots... well, try it to see by yourself! :-) + //+ Random number function by Michael Sargent (USA), msargent@moose.uvm.edu + //+ No SVGA drivers needed. + //+ + //+ INSTRUCTIONS: press 'n' or 'N' to skip to the next plot; any other key + //+ will stop execution. + //+ OBS: Not all images are interesting. Skip to the next, then. + //+-------------------------------------------------------------------------+ #include #include #include #include double qsrandom(void); void main(void) { int i, f, nx, ny, sign, GraphDriver=DETECT, GraphMode; int ipal1[13] = {0,1,1,9,9,25,25,11,11,31,31,63,63}; int ipal2[13] = {0,4,4,36,36,52,52,38,38,54,54,62,63}; char key; double a, b, c, d, rnd1, rnd2, pi, p2, p4, p6, x, y; double x1, y1, sx, sy, sx4, sy4; pi = 3.141592653589793; initgraph(&GraphDriver,&GraphMode,"C:\\BORLANDC\\BGI"); do { rnd1 = qsrandom(); if (rnd1 >= 0.5) for (i=0;i<=12;i++) setpalette(i,ipal1[i]); else for (i=0;i<=12;i++) setpalette(i,ipal2[i]); rnd1 = qsrandom(); rnd2 = qsrandom(); a = rnd2 - rnd1; rnd1 = qsrandom(); rnd2 = qsrandom(); b = rnd2 - rnd1; rnd1 = qsrandom(); rnd2 = qsrandom(); c = rnd2 - rnd1; rnd1 = qsrandom(); rnd2 = qsrandom(); d = rnd2 - rnd1; x = qsrandom(); y = qsrandom(); p2 = 2.0*pi; p4 = 4.0*pi; p6 = 6.0*pi; rnd1 = qsrandom(); if (rnd1 >= 0.5) sign = 1; else sign = -1; do { sx = p2*x; sy = p2*y; sx4 = p4*x; sy4 = p4*y; x1 = a*sin(sx) + sign*b*sin(sx)*cos(sy) + c*sin(sx4) + d*sin(p6*x)*cos(sy4); y1 = a*sin(sy) + sign*b*sin(sy)*cos(sx) + c*sin(sy4) + d*sin(p6*y)*cos(sx4); nx = (int)(128.0*(x1 + 2.5)); ny = (int)(480.0*(y1 + 1.6)/3.2); f = getpixel(nx,ny); if (f < 12) f++; putpixel (nx,ny,f); x = x1; y = y1; } while (!kbhit()); key = getch(); cleardevice(); } while ((key == 'n') || (key == 'N')); closegraph(); } double qsrandom(void) //* Random number generator by Mike Sargent. *// { int random_integer, temp_integer; double random_double, temp_double; random_integer = random(RAND_MAX); random_double = (double)random_integer / RAND_MAX; temp_integer = random(30519); temp_double = (double)temp_integer / 1000000000L; random_double += temp_double; return(random_double); }