diff --git a/mandel_classic.c b/mandel_classic.c index a92c5d8..d65bc5c 100644 --- a/mandel_classic.c +++ b/mandel_classic.c @@ -131,23 +131,23 @@ int mandelbrot_point(int res_x, int res_y, int image_x, int image_y, float zoom, float pos_y = map_y(image_y, res_y, zoom); float x = 0.0; float y = 0.0; - float q, x_term; - float xtemp, xx, yy; + float q, x_term, pos_y2; + float xtemp, xx, yy, xplusy; #ifdef CACHE int storeable = 1; #endif int iteration = 0; - yy = y * y; - // Period-2 bulb check - if (((x + 1) * (x + 1) + yy) < 0.0625) return 0; + x_term = pos_x + 1.0; + pos_y2 = pos_y * pos_y; + if ((x_term * x_term + pos_y2) < 0.0625) return 0; // Cardioid check - x_term = x - 0.25; - q = x_term * x_term + yy; + x_term = pos_x - 0.25; + q = x_term * x_term + pos_y2; q = q * (q + x_term); - if (q > (0.25 * yy)) return 0; + if (q < (0.25 * pos_y2)) return 0; #ifdef CACHE // Look up our cache @@ -165,13 +165,14 @@ int mandelbrot_point(int res_x, int res_y, int image_x, int image_y, float zoom, while (iteration < max_iteration) { xx = x * x; + yy = y * y; + xplusy = x + y; if ((xx) + (yy) > (4.0)) break; - y = (x + y) * (x + y) - xx - yy; + y = xplusy * xplusy - xx - yy; y = y + pos_y; xtemp = xx - yy + pos_x; x = xtemp; - yy = y * y; iteration++; } diff --git a/mandelbrot_kernel.cl b/mandelbrot_kernel.cl index 9a18e26..f3e5c52 100644 --- a/mandelbrot_kernel.cl +++ b/mandelbrot_kernel.cl @@ -21,19 +21,39 @@ __kernel void fractal_point(__global const int *res_x, float pos_y = map_y(image_y, *res_y, *zoom); float x = 0.0; float y = 0.0; + float q, x_term; + + // Period-2 bulb check + if (((pos_x + 1.0) * (pos_x + 1.0) + pos_y * pos_y) < 0.0625) + { + graph_line[image_x] = 0; + return; + } + + // Cardioid check + x_term = pos_x - 0.25; + q = x_term * x_term + pos_y * pos_y; + q = q * (q + x_term); + if (q < (0.25 * pos_y * pos_y)) + { + graph_line[image_x] = 0; + return; + } int iteration = 0; int max_iteration = 256; - float xtemp, xx, yy; + float xtemp, xx, yy, xplusy; while (iteration < max_iteration) { xx = x * x; yy = y * y; + xplusy = x + y; if ((xx) + (yy) > (4.0)) break; xtemp = xx - yy + pos_x; - y = 2.0 * x * y + pos_y; + y = xplusy * xplusy - xx - yy; + y = y + pos_y; x = xtemp; iteration++; diff --git a/mandelclassic b/mandelclassic index ba3552f..cd084c5 100755 Binary files a/mandelclassic and b/mandelclassic differ