Fractal surprise from complex function iteration: The code

//  here is the program for the last post

//  Fractal surprise from complex function iteration

//   simply use it in processing 1.5 (I don’t know if it works in the new version 2.)

// you can download it from processing.org

float range, c,step;
int n, iter, count;
float rsqmax;

void setup() {
size(600, 600);
c=0.4;
step=0.002;
iter=40;
rsqmax=100;
range=1.2;
count=0;
}

void draw() {
int i, j, k;
float d=2*range/width;
float x, y, h;
float phi, phiKor;                             //  phiKor is the trivial phase change to subtract
colorMode(HSB, 400, 100, 100);
loadPixels();
for (j=0;j<height;j++) {
for (i=0;i
y=-range+d*j;
x=-range+d*i;
phiKor=0;
for (k=0;k<iter;k++) {
if (x*x+y*y>rsqmax) {
break;
}
phiKor+=atan2(y, x);
h=x*x-y*y+c;
y=2*x*y;
x=h;
}
phi=atan2(y, x)-phiKor;    //  correction
phi=0.5*phi/PI;
phi=(phi-floor(phi))*2*PI;  //  calculate phase phi mod 2PI
pixels[i+j*width]=color(phi/PI*200, 100, 100);
}
}
updatePixels();
//  saveFrame(“a-####.jpg”);
println(count+” “+c);
c-=step;
if (c<0) {
noLoop();
}
count++;
}

This entry was posted in Self-similarity and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s