Created
November 7, 2012 18:13
-
-
Save ReaperUnreal/4033328 to your computer and use it in GitHub Desktop.
Mandelbrot code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void doFractal(float xpos, float ypos, float zoom = 1.0f) | |
{ | |
//doing Mandelbrot | |
Mandelbrot m(maxIter, escape); | |
const float scale = 1.0f / zoom; | |
const float floatWidth = 3.5f * scale; //zoom = 1 should be -2.5 to 1 in X | |
const float floatHeight = floatWidth * static_cast<float>(height) / static_cast<float>(width); | |
const float minX = xpos - (floatWidth * 0.5f); | |
const float minY = ypos - (floatHeight * 0.5f); | |
const float invfw = 1.0f / static_cast<float>(width); | |
const float invfh = 1.0f / static_cast<float>(height); | |
const int size = width * height; | |
#pragma omp parallel for schedule(guided, 1024) default(none) shared(picture) firstprivate(m) | |
for(int i = 0; i < size; i++) | |
{ | |
int y = i / width; | |
int x = i - (y * width); | |
float sfx = static_cast<float>(x) * invfw; //0-1 | |
float sfy = static_cast<float>(y) * invfh; //0-1 | |
float fx = minX + (sfx * floatWidth); | |
float fy = minY + (sfy * floatHeight); | |
picture[i] = m.escape(complex<float>(fx, fy)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float Mandelbrot::escape(const complex<float> &c) const | |
{ | |
complex<float> z(0.0f, 0.0f); | |
int i = 0; | |
for(; i < max; i++) | |
{ | |
z = z * z + c; | |
if(norm(z) > sqrRadius) | |
{ | |
break; | |
} | |
} | |
float mu = static_cast<float>(i) - adjustment; | |
return mu * invmi; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment