This is a small sample program that will work on a basic
compiler.
This is a larger sample program that will work on a C++ compiler.
"Complex math by Tim L. Helmer"
"bstuff.h by Brian Allan & Gary Allan"
#include <bstuff.h> /* For graphics library functions */
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void set_graph(void); /* Initialize graphics */
void get_key(void);
void fractal(void);
void main(void)
{randomize();
set_graph();
do{fractal();}while(1);
get_key();}
void fractal(void)
{int i,p,q;
double x,ox,y,a,b,c,d,e,f,g,h,rt1,it1,rb1,ib1,b1,gg,ss,uu;
double j,k,l,m,n,o,b2,rt2,it2,rb2,ib2; //double t =
(float)random(1001)/1000.0;
double t = 0.5; // vary t (0<t<1) for
different homotopys
double aa,bb,cc,dd;
double MMax_p = 149;
double MMax_q = 99;
double R = 0.001;
double RR = 200;
int its = 160;
a = 1.7; //((float)random(550)/100.0)-1.0;
b = 0; //a from -1 to 4.5 for
mag1 and mag2
//aa = -6.0,bb = -4.5,cc = 6.0,dd = 4.5;
//aa = -12.0,bb = -9.0,cc = 12.0,dd = 9.0;
aa=-12.0+(t*6.0);cc=-aa;
bb=-9.0+(t*4.5);dd=-bb;
for (p=0; p<MMax_p; p++) //the
outer loops for p and q are the screen coordinates.
{
ox = aa + ((cc-aa)*(p/MMax_p));
for (q=0; q<MMax_q; q++)
{
x=ox;
y = bb + ((dd-bb)*(q/MMax_q));
if (kbhit()==-1){exit(0);}
for (i=1; i<its; i++)
{
c=x*x-y*y;d=2*x*y; //start the math and the
iterations.
e=a*a-b*b;f=2*a*b;
g=c*c-d*d;h=2*c*d;
rt1=g+1+e+2*(c*a-b*d-c-a);
it1= h+f+2*(c*b+d*a-d-b);
rb1= e+4+4*(c+x*a-y*b-2*x-a);
ib1= f+4*(d+x*b+a*y-2*y-b);
b1=1/(rb1*rb1+ib1*ib1);
j=x*c-y*d;k=x*d+y*c;
l=j+2+e+3*(x*a-y*b-x-a);
m= k+f+3*(x*b+a*y-y-b);
n= e+3+3*(c+x*a-y*b-2*x-a);
o= f+3*(d+x*b+a*y-2*y-b);
rt2=l*l-m*m;it2=2*l*m;
rb2=n*n-o*o;ib2=2*n*o;
b2=1/(rb2*rb2+ib2*ib2);
x = t*(rt1*rb1+it1*ib1)*b1+(1-t)*(rt2*rb2+it2*ib2)*b2; //new x
y = t*(it1*rb1-rt1*ib1)*b1+(1-t)*(it2*rb2-rt2*ib2)*b2; //new y
gg=x*x+y*y;ss=gg+1;uu=ss-2*x; //test distance from
roots
if (gg>RR) {putPixb(p,q,i+80);break;}
if (uu<R) {putPixb(p,q,i+7);break;}
}/*next i*/
if(i==its) putPixb(p,q,0);
}/*next q*/
}/*next p*/
}//end of main
void set_graph(void)
{int p;int col;setMode(0x13);writeColourReg(0, 0,0,0);col=20;
for (p=1; p<64; p++)
{col=col+1;writeColourReg(p, col*3,0,0);}
col=128;
for (p=64; p<128; p++)
{col=col-1;writeColourReg(p, 0,col,0);}
col=5;
for (p=128; p<192; p++)
{col=col+1;writeColourReg(p, col*3,col*2,0);}
col=5;
for (p=192; p<256; p++)
{col=col+1;writeColourReg(p, 0,0,col*2);}
}
//void set_graph(void)
//{
// int graphdriver = VGA, graphmode = VGAHI;
// struct palettetype pal;
// int i, j;
// initgraph(&graphdriver, &graphmode, "");
// getpalette(&pal);
// for (i=0; i<pal.size; i++)
// {setrgbpalette(pal.colors[i], i*0, i*4, i*0); }
//}
void get_key(void)
{getch();}