//+-------------------------------------------------------------------------+ //+ Order & Beauty from Chaos - Program FASTBALL.C + //+ + //+ 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). + //+ + //+ Plots thousands of randomly-generated spheres and rosettes, some very + //+ intriguing (rotating and pulsating). + //+ Random number function by Michael Sargent (USA), msargent@moose.uvm.edu + //+ No SVGA drivers needed. + //+ + //+ INSTRUCTIONS: press 'n' or 'N' to see the next plot; any other key will + //+ stop the execution. + //+-------------------------------------------------------------------------+ #include #include #include #include double qsrandom(void); void main(void) { double ra, rnd1, in, in2, an, an2, x, y, c1, c2; int ipal1[6] = {1,9,25,11,31,63}, ipal2[6] = {4,36,52,38,54,62}; int i, k, nx, ny, GraphDriver=DETECT, GraphMode; char key; initgraph(&GraphDriver,&GraphMode,"C:\\BORLANDC\\BGI"); c1 = 640.0/3.1; c2 = 480.0/2.1; do { rnd1 = qsrandom(); if (rnd1 >= 0.5) for (i=0;i<=5;i++) setpalette(i,ipal1[i]); else for (i=0;i<=5;i++) setpalette(i,ipal2[i]); in = 6.24*qsrandom(); in2 = 6.24*qsrandom(); cleardevice(); setbkcolor(BLACK); do { an = an + in; an2 = an2 + in2; ra = sin(an2); x = ra*sin(an); y = ra*cos(an); nx = c1*(x + 1.55); ny = c2*(y + 1.05); k = getpixel(nx,ny); if (k < 6) putpixel (nx,ny,(k+1)); } while (!kbhit()); key = getch(); } while ((key == 'n') || (key == 'N')); closegraph(); } double qsrandom(void) { 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); }