Title: Bizzarre Mandelbrot Result Post by: asimes on February 14, 2012, 09:02:18 AM I made a Mandelbrot program in Processing a little while ago that tests every pixel on the screen using z = sq(z)+c. It works just fine but I did not know how to generalize it to 3D. I found a website that had a very simple looking different method of testing points to see if they are part of the Mandelbrot set (and a generalization to 3D) and followed the instructions. To my surprise it made a different fractal. The website is here:
http://www.skytopia.com/project/fractal/mandelbrot.html#pandora What I wrote is below. It's in the Java that Processing uses (the important part is in the while statement, I know that the rest works correctly): float xmin = -2.5; float ymin = -2; float wh = 4; int maxIterations = 100; void setup() { size(400, 400, P2D); noLoop(); } void draw() { loadPixels(); float xmax = xmin+wh; float ymax = ymin+wh; float dx = (xmax-xmin)/width; float dy = (ymax-ymin)/width; float x = xmin; for (int i = 0; i < width; i++) { float y = ymin; for (int j = 0; j < height; j++) { float nx = x; float ny = y; int n = 0; while (n < maxIterations) { float a = atan2(ny, nx); float d = sqrt(sq(nx)+sq(ny)); nx = cos(a*2)*sq(d)+cos(a)*d; ny = sin(a*2)*sq(d)+sin(a)*d; if (sq(nx)+sq(ny) > 4) break; n++; } if (n == maxIterations) pixels[i+j*width] = 0xffffff; else pixels[i+j*width] = 0; y += dy; } x += dx; } updatePixels(); } One last thing that was even more strange to me is that if I change two lines in the while statement to subtract Step 3 from the instructions (instead of add) I get something that looks like a Mandelbrot Set reflected over the Y axis (the left half reflects to the right). The changed lines become: nx = cos(a*2)*sq(d)-cos(a)*d; ny = sin(a*2)*sq(d)-sin(a)*d; Any help or suggestions as to what might have gone wrong would be greatly appreciated. Title: Re: Bizzarre Mandelbrot Result Post by: ker2x on February 14, 2012, 02:37:42 PM woooooooo some processing !
I'll try and check that as soon as a i have some free time. (i'm at work right now ...) Title: Re: Bizzarre Mandelbrot Result Post by: ker2x on February 14, 2012, 04:01:28 PM hooooooo fun ! (played with the code)
Code: float xmin = -2.5; Title: Re: Bizzarre Mandelbrot Result Post by: ker2x on February 14, 2012, 04:19:45 PM problem solved :
Code: float xmin = -2.5; please see STEP 4 : STEP 4: Finally, perform the above 3 steps again, but this time with the yellow star point replacing the old blue point (however, make sure you always use the ORIGINAL blue arrow for the final movement in step 3 (i.e. always move it by x=x+0.2 y=y+0.4). Once you've gotten the new "yellow star" point, do the same again, and AGAIN. the original is what i called "oa" and "od" in my code. I'm surprised i could solve this problem, as i don't really understand the explanation on http://www.skytopia.com/project/fractal/mandelbrot.html#pandora Title: Re: Bizzarre Mandelbrot Result Post by: ker2x on February 14, 2012, 04:43:24 PM i realise that i added a lot of modification of my own.
so here is the patch from your original code : float xmin = -2.5; float ymin = -2; float wh = 4; int maxIterations = 100; void setup() { size(400, 400, P2D); noLoop(); } void draw() { loadPixels(); float xmax = xmin+wh; float ymax = ymin+wh; float dx = (xmax-xmin)/width; float dy = (ymax-ymin)/width; float x = xmin; for (int i = 0; i < width; i++) { float y = ymin; for (int j = 0; j < height; j++) { float nx = x; float ny = y; int n = 0; float oa = atan2(ny, nx); float od = sqrt(sq(nx)+sq(ny)); while (n < maxIterations) { float a = atan2(ny, nx); float d = sqrt(sq(nx)+sq(ny)); nx = cos(a*2)*sq(d)+cos(oa)*od; ny = sin(a*2)*sq(d)+sin(oa)*od; if (sq(nx)+sq(ny) > 4) break; n++; } if (n == maxIterations) pixels[i+j*width] = 0xffffff; else pixels[i+j*width] = 0; y += dy; } x += dx; } updatePixels(); } Title: Re: Bizzarre Mandelbrot Result Post by: ker2x on February 14, 2012, 05:00:51 PM can you please share the code when you'll extrapolate to the 3rd dimension ? :)
Title: Re: Bizzarre Mandelbrot Result Post by: asimes on February 14, 2012, 05:53:28 PM Oh whoops, I never was too good at following the end of instructions, ha ha. Thank you for looking through it, I will post the 3D version if I wrap my head around it. Out of curiosity, do you know the name of any of the fractals that showed up?
Title: Re: Bizzarre Mandelbrot Result Post by: ker2x on February 15, 2012, 10:44:04 AM Oh whoops, I never was too good at following the end of instructions, ha ha. Thank you for looking through it, I will post the 3D version if I wrap my head around it. Out of curiosity, do you know the name of any of the fractals that showed up?
In most of my tests, it looked like Julia. Title: Re: Bizzarre Mandelbrot Result Post by: asimes on February 17, 2012, 12:57:00 AM I think I figured out the 3D one, I'm not really sure to be honest. The problem is that I don't know how to represent it nicely in Processing. Right now I have it representing only points that reached the max iteration count and I don't know how to light it properly.
I spent a few days wrapping my head around getting x, y, z coordinates to be spherical coordinate angles. If I generalized it correctly then this should be the image from that link (the white fractal with the glowing orange aura): http://www.skytopia.com/project/fractal/mandelbrot.html#pandora float xmin = -2; float ymin = -2; float zmin = -2; float wh = 4; int boxLength = 200; int maxIterations = 1; int screenSize = 400; float temp = 0; void setup() { size(screenSize, screenSize, P3D); noLoop(); } void draw() { background(255); translate((screenSize-boxLength)/2, (screenSize-boxLength)/2); float xmax = xmin+wh; float ymax = ymin+wh; float zmax = zmin+wh; float dx = (xmax-xmin)/boxLength; float dy = (ymax-ymin)/boxLength; float dz = (zmax-zmin)/boxLength; float x = xmin; for (int i = 0; i < boxLength; i++) { float y = ymin; for (int j = 0; j < boxLength; j++) { float z = zmin; for (int k = 0; k < boxLength; k++) { float rad = sqrt(x*x+y*y+z*z); float phi = atan2(z, x); float phiLength = sqrt(x*x+z*z); float theta = atan2(phiLength, y); float nx = x; float ny = y; float nz = z; int n = 0; while (n < maxIterations) { float nRad = sqrt(nx*nx+ny*ny+nz*nz); float nPhi = atan2(nz, nx); float nPhiLength = sqrt(nx*nx+nz*nz); float nTheta = atan2(nPhiLength, ny); nx = cos(nPhi*2)*sin(nTheta*2)*nRad*nRad; ny = cos(nTheta*2)*nRad*nRad; nz = sin(nPhi*2)*sin(nTheta*2)*nRad*nRad; nx += cos(phi)*sin(theta)*rad; ny += cos(theta)*rad; nz += sin(phi)*sin(theta)*rad; if (nx*nx+ny*ny+nz*nz > 4) break; n++; } if (n == maxIterations) point(i, j, k); z += dz; } y += dy; } x += dx; } println("Done"); } Title: Re: Bizzarre Mandelbrot Result Post by: asimes on February 17, 2012, 01:06:06 AM This is a little better:
EDIT: Changed a bit: float xmin = -2; float ymin = -2; float zmin = -2; float wh = 4; int boxLength = 200; int maxIterations = 255; int screenSize = 400; float temp = 0; void setup() { size(screenSize, screenSize, P3D); noStroke(); noLoop(); } void draw() { background(255); translate((screenSize-boxLength)/2, (screenSize-boxLength)/2); float xmax = xmin+wh; float ymax = ymin+wh; float zmax = zmin+wh; float dx = (xmax-xmin)/boxLength; float dy = (ymax-ymin)/boxLength; float dz = (zmax-zmin)/boxLength; float x = xmin; for (int i = 0; i < boxLength; i++) { float y = ymin; for (int j = 0; j < boxLength; j++) { float z = zmin; for (int k = 0; k < boxLength; k++) { float rad = sqrt(x*x+y*y+z*z); float phi = atan2(z, x); float phiLength = sqrt(x*x+z*z); float theta = atan2(phiLength, y); float nx = x; float ny = y; float nz = z; int n = 0; while (n < maxIterations) { float nRad = sqrt(nx*nx+ny*ny+nz*nz); float nPhi = atan2(nz, nx); float nPhiLength = sqrt(nx*nx+nz*nz); float nTheta = atan2(nPhiLength, ny); nx = cos(nPhi*2)*sin(nTheta*2)*nRad*nRad; ny = cos(nTheta*2)*nRad*nRad; nz = sin(nPhi*2)*sin(nTheta*2)*nRad*nRad; nx += cos(phi)*sin(theta)*rad; ny += cos(theta)*rad; nz += sin(phi)*sin(theta)*rad; if (nx*nx+ny*ny+nz*nz > 4) break; n++; } if (n != 0) { translate(i, j, k); fill(n*19%255, n*11%255, n*7%255, n); box(1); translate(-i, -j, -k); } z += dz; } y += dy; } x += dx; } println("Done"); } Title: Re: Bizzarre Mandelbrot Result Post by: asimes on February 17, 2012, 01:45:53 AM It took a little while (a few min) but setting:
boxLength = 500; screenSize = 800; Then the rendering section to: if (n > 10) { translate(i, j, k); fill(n*3%255, n*2%255, n%255, n); box(1); translate(-i, -j, -k); } Makes a much more reasonable image. Still experimenting with color, transparency, and hopefully soon lighting Title: Re: Bizzarre Mandelbrot Result Post by: ker2x on February 17, 2012, 11:24:01 PM Thank you, i will try ! ;D
Title: Re: Bizzarre Mandelbrot Result Post by: ker2x on February 21, 2012, 07:04:02 PM huh... you're checking 500x500x500 points :))) |