From d4f0f8d85b2e8912f378270dc846dd0a4369acdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Cuevas?= Date: Sun, 1 Sep 2013 02:57:00 +0200 Subject: [PATCH] Made sure cardioid check and period-2 check worked and added it to the OpenCL version. Made the calculation the same as the classic in OpenCL version too. --- mandel_classic.c | 21 +++++++++++---------- mandelbrot_kernel.cl | 24 ++++++++++++++++++++++-- mandelclassic | Bin 12502 -> 12614 bytes 3 files changed, 33 insertions(+), 12 deletions(-) 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 ba3552fc7ea36e2a45d9dbf029c32c4922bd0bbb..cd084c5617f96fa5ff2b135be906112b1a8989bf 100755 GIT binary patch delta 3054 zcmZuze{2-T72aKQ;r!z~d-nabjeNoO`8dphtrDCR$UzOgppYO`%Gol`K~+RrHNqCu zQKe!Biohss9bTHI}A1RUX5o)VduHT#6 zB?n}rnK$3}-n@D9W_ETy-hF9LcR-6Qc`5jty0uyUPhu7AL#SaxANIy1ANG=_ z`ir6l9X05vmmX7F>?G(-^$o|V*LUl`e=g_yBdMJyo_qVfH}%(BzuOWWA4-N)~gy!QdV8oXU$o=PkswWt3HOSx7REzNl4_;a%Sn_ey8 zO6Z?fw~be6mQFgi*iD|?0$cW&Zn_RO0+zj*DCr5&R)&`xA&^(^fqjYB(=r7gD5zErK_gVit;dejQ6oJIhjVO`h+p3GC3ykHO3m_ zxWuE3IjPA$iH8_3VtiWS3&0)wcvq6$k~q%>obP0(#BVX?xRd)OKFgRho{UL+ig7OE zZ4#ek%sEenB|gD8pYbY*4>K-c?34IMcHh&=J{uFdB-+@3ww#MsVwOycc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