King.cpp
/* The King's Dream
   Equations and Constants from Chaos in Wonderland, by Clifford Pickover, 1994
   programmed by James Rankin, monty@nrv.net
*/

#include 
#include 
#include 
#include 
#include 
#include 
#include 

int huge detectvga256(void);
void runfractal(void);
void getvars(void);

double a = -0.966918;
double b = 2.879879;
double c = 0.765145;
double d = 0.744728;

void main() {
	int graphdriver = installuserdriver("SVGA256", detectvga256);
	graphdriver = DETECT;
	int graphmode;
	getvars();
	initgraph(&graphdriver, &graphmode, "");
	runfractal();
	sound(440);
	delay(50);
	nosound();
	getch();
	closegraph();
}

void getvars(void) {
	clrscr();
	cout << "The King's Dream  -   formulas by Clifford Pickover\n";
	cout << "Coded in C++ by James Rankin\n";
	cout << "Four constants are needed to generate an image.\n";
	cout << "You may either use the default values, to generate the King's\n";
	cout << "dream, or you may specify your own.\n";
	cout << "Do you want to use the default values?  Y/N\n";
	int thekey = 0;
	do {
		if (kbhit() != 0) thekey = getch();
	} while ((thekey != 89) & (thekey != 121) & (thekey != 78) & (thekey != 110));
	if ((thekey == 78) | (thekey == 110)) {
	cout << "\n";
	cout << "Input A ( A > -3 )\n";
	cin >> a;
	cout << "Input B ( B < 3 )\n";
	cin >> b;
	cout << "Input C ( C > 0.5 )\n";
	cin >> c;
	cout << "Input D ( D < 1.5 )\n";
	cin >> d;
	}
}

void runfractal(void) {
double xnew, ynew, xold = 0.1, yold = 0.1;
	for (double loopy = 0; loopy != 10000000; loopy++) {
		xnew = sin(yold * b) + c * sin(xold * b);
		ynew = sin(xold * a) + d * sin(yold * a);
		xold = xnew;
		yold = ynew;
		putpixel((int)(xold*180+512),(int)(yold*250+384),77);
		if (kbhit() != 0) break;
	}
}

int huge detectvga256(void) {
	return 4;
}//of method