//+-------------------------------------------------------------------------+ //+ Program TCHEBY.CPP - November 13, 1994 + //+ + //+ By Fausto Arinos de Almeida Barbuto, Rio de Janeiro, RJ, BRAZIL + //+ E-mails: BJ06@C53000.PETROBRAS.ANRJ.BR and barbuto@ax.ibase.org.br + //+ + //+ Repeated iterations over the Tschebysheff function over the real domain.+ //+ Based on Pseudocode 15.1 (see REFERENCE below) + //+ Press ESC at any time to fade the screen out and quit. + //+ + //+ REFERENCE: Pickover, Clifford A. "Computers, Pattern, Chaos and Beauty" + //+ 1990, St.-Martin's Press, pp. 293. + //+ + //+ Uses SVGA256.BGI by Jordan Powell Hargrave and fade-out routine by + //+ Michael E. Sargent and Quintessential Sophistry. + //+ + //+ Version for spanky.triumf.ca (142.90.112.1), Vancouver, B.C. Canada. + //+*************************************************************************+ #include #include #include #include #include #include "svga256.h" int Video; /* Global variable */ double Chebyshev(int, double); void fade(void); int huge DetectSVGA256() { printf("\n Which video mode would you like to use? \n\n"); printf(" 0 - 320x200x256\n"); printf(" 1 - 640x400x256\n"); printf(" 2 - 640x480x256 (suggested when available)\n"); printf(" 3 - 800x600x256\n"); printf(" 4 - 1024x768x256\n\n> "); scanf("%d",&Video); if ((Video>4) || (Video<0)) Video = 2; return Video; } void main() { double xmin=-1.0, xmax=1.0, ymin=-1.0, ymax=1.0; double xold, yold, r, deltap, deltaq, p, q, x, y, T1, T2, h; unsigned int maxiter; register int k, np, nq; int npix, npiy, order, initcolour, graphdriver=DETECT, graphmode; // clrscr(); printf("\n Program CHEBY.C - By Fausto A. A. Barbuto, November 1994"); printf("\n\n WARNING: Some combinations of high 'order', 'h' and"); printf(" 'maxiter' may cause\n overflow before the end"); printf(" of the execution."); printf("\n\n Select the order of the polynomial (3 <= order <= 20):"); printf("\n\n> "); scanf("%d",&order); if ((order < 3) || (order > 20)) order = 10; printf("\n Select a step 'h', 0.0 < h < 1.0 (suggested: 0.1):\n\n> "); scanf("%lf",&h); printf("\n\n Select the maximum number of iterations"); printf("\n (Suggestion: start with 20, then increase):\n\n> "); scanf("%u",&maxiter); clrscr(); printf("\n Choose a colour scheme:\n\n 'Tropical' : Enter 30\n"); printf(" Shades of gray: Enter 16\n Your own : "); printf("Enter ???\n\n> "); scanf("%d",&initcolour); installuserdriver("Svga256",DetectSVGA256); initgraph(&graphdriver,&graphmode,"C:\\BORLANDC\\BGI"); cleardevice(); if (Video == 0) {npix=320; npiy=200;} if (Video == 1) {npix=640; npiy=400;} if (Video == 2) {npix=640; npiy=480;} if (Video == 3) {npix=800; npiy=600;} if (Video == 4) {npix=1024; npiy=768;} deltap = (xmax-xmin)/(double)(npix-1); deltaq = (ymax-ymin)/(double)(npiy-1); for (np=0; np<=npix-1; np++) { p = xmin + (double)np*deltap; for (nq=0; nq<=npiy-1; nq++) { q = ymin + (double)nq*deltaq; x = p; y = q; k = 0; do { xold = x; yold = y; T1 = Chebyshev(order,yold); x = x - h*sin(T1); T2 = Chebyshev(order,xold); y = y + h*sin(T2); r = sqrt(T1*T1 + T2*T2); k++; if (r >= maxiter) { putpixel(np,nq,(initcolour+k)); } if (k == maxiter) { putpixel(np,nq,1); } } while (r<=maxiter && k<=maxiter); } if (kbhit()) break; } getch(); fade(); closegraph(); } double Chebyshev(int nn, double xx) { double z3, Tc[20], T; register int ii; z3 = xx*xx*xx; Tc[2] = 2.0*xx*xx - 1.0; Tc[3] = 4.0*z3 - 3.0*xx; for (ii=3;ii<=nn;ii++) { Tc[ii+1] = 2.0*xx*Tc[ii] - Tc[ii-1]; T = Tc[ii+1]; } return T; } //+======================================================================+ // Fade-out routine by Michael E. Sargent & The Quintessential Sophistry + //=======================================================================+ #pragma warn -eff void fade(void) { int a, b, p1, p2, p3; for (a=0; a<64; a++) { for (b=0; b<256; b++) { outp(0x3C7, b); p1 = inp(0x3C9); p2 = inp(0x3C9); p3 = inp(0x3C9); outp (0x3C8, b); if (p1 > 0) outp(0x3C9, p1 - 1); else outp(0x3C9, 0); if (p2 > 0) outp(0x3C9, p2 - 1); else outp(0x3C9, 0); if (p3 > 0) outp(0x3C9, p3 - 1); else outp(0x3C9, 0); } delay(75); } } #pragma warn +eff