Skip to content

Instantly share code, notes, and snippets.

@robertmaxwilliams
Created June 30, 2020 16:04
Show Gist options
  • Save robertmaxwilliams/f7dce04a6580b8a81237ee27ffc3a153 to your computer and use it in GitHub Desktop.
Save robertmaxwilliams/f7dce04a6580b8a81237ee27ffc3a153 to your computer and use it in GitHub Desktop.
int shift(int x, int s) {
if (s > 0) {
return x<<s;
} else if (s < 0) {
return x>>s;
} else {
return x;
}
}
int bitand(int x, int y) {
return x&y;
}
for (int i = 0; i < WINDOW_WIDTH; i++) {
for (int j=0; j< WINDOW_HEIGHT; j++) {
int r=0;
int g=0;
int b=0;
double xc = -4.2 + 0.01 * (WINDOW_HEIGHT-j); // should max out at 4.2
double yc = -3.0 + 0.01 * i; // should max out at 3.0
complex double z = scale*xc + scale*yc*I;
int trapped = 0;
int v = 553;
int iter = 1;
while (!trapped) {
v = 36969*bitand(v, 65535)+shift(v, -16);
double rr = (double)(shift(v, 16)+1)/(pow(2.0,32)+2);
v = 36969*bitand(v, 65535)+shift(v, -16);
double s = (double)(shift(v, 16)+1)/(pow(2.0, 32)+2);
z = (rr*(z*z*z-1)+1)/(s*(z*z-1)+1);
if (fabs(cabs(z)-1)<0.1) {
g = 8*iter + (carg(z)+3.14)*44;
r = 16*iter + (int)fabs((creal(z)-0.893943)*160);
b = 16*iter + (int)fabs((cimag(z)-0.000110)*1600);
trapped = 1;
}
if (iter > 16) {
trapped = 1;
}
iter += 1;
}
}
}
@robertmaxwilliams
Copy link
Author

Also I found the code for coloring it almost exactly like yours:
r = g = b = 256-1000*(fabs(cabs(z)-1)) + (carg(z) > 0 ? 20 : -20);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment