summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Pinot <ngc891@gmail.com>2013-11-06 07:59:31 +0900
committerJerome Pinot <ngc891@gmail.com>2013-11-06 07:59:31 +0900
commit3969666fc054cdb315ad4fc3df8d4d0157eb3b8e (patch)
treef6c1cd8e7ce6b638c9e94aaa0cbf71eb21d5269c
parent1e3fe6b820c04ffeaa2d085fc41d2d606fed16dc (diff)
Add mandelbrot cubic and quadratic
-rw-r--r--src/formula.c58
1 files changed, 55 insertions, 3 deletions
diff --git a/src/formula.c b/src/formula.c
index 5e0d51f..ead4557 100644
--- a/src/formula.c
+++ b/src/formula.c
@@ -32,6 +32,8 @@ extern uint32_t palette[256];
32extern map_struct map; 32extern map_struct map;
33static int formula(char *set, double x, double y); 33static int formula(char *set, double x, double y);
34static int mandelbrot(double x0, double y0); 34static int mandelbrot(double x0, double y0);
35static int mandelbrot3(double x0, double y0);
36static int mandelbrot4(double x0, double y0);
35static int julia(double x, double y); 37static int julia(double x, double y);
36 38
37/* draw the fractal */ 39/* draw the fractal */
@@ -75,7 +77,6 @@ draw(void *data, Ecore_Thread *thread __UNUSED__)
75 evas_object_focus_set(win.img, EINA_TRUE); 77 evas_object_focus_set(win.img, EINA_TRUE);
76} 78}
77 79
78
79/* wrapper to call the right formula */ 80/* wrapper to call the right formula */
80static int 81static int
81formula(char *set, double x, double y) 82formula(char *set, double x, double y)
@@ -84,6 +85,14 @@ formula(char *set, double x, double y)
84 { 85 {
85 return mandelbrot(x, y); 86 return mandelbrot(x, y);
86 } 87 }
88 else if (strcmp(set, "mandelbrot3") == 0)
89 {
90 return mandelbrot3(x, y);
91 }
92 else if (strcmp(set, "mandelbrot4") == 0)
93 {
94 return mandelbrot4(x, y);
95 }
87 else if (strcmp(set, "julia") == 0) 96 else if (strcmp(set, "julia") == 0)
88 { 97 {
89 return julia(x, y); 98 return julia(x, y);
@@ -112,7 +121,51 @@ mandelbrot(double x0, double y0)
112 return i; 121 return i;
113} 122}
114 123
115/* 1: Julia set */ 124/* 1: Mandelbrot cubic set */
125static int
126mandelbrot3(double x0, double y0)
127{
128 int i = 0;
129 double x = 0;
130 double y = 0;
131 double x_tmp;
132 double module = 0;
133
134 while (i<DEPTH && module <= 4)
135 {
136 x_tmp = x*x*x - 3*x*y*y + x0;
137 y = 3*x*x*y - y*y*y + y0;
138 x = x_tmp;
139 module = x*x + y*y;
140 i++;
141 }
142 return i;
143}
144
145/* 2: Mandelbrot quadratic set */
146static int
147mandelbrot4(double x0, double y0)
148{
149 int i = 0;
150 double x = 0;
151 double y = 0;
152 double x_tmp;
153 double module = 0;
154
155 while (i<DEPTH && module <= 4)
156 {
157 x_tmp = x*x*x*x + y*y*y*y - 6*x*x*y*y + x0;
158 y = 4*x*x*x*y - 4*x*y*y*y + y0;
159 x = x_tmp;
160 module = x*x + y*y;
161 i++;
162 }
163 return i;
164}
165
166
167
168/* 3: Julia set */
116static int 169static int
117julia(double x, double y) 170julia(double x, double y)
118 { 171 {
@@ -133,5 +186,4 @@ julia(double x, double y)
133 return i; 186 return i;
134} 187}
135 188
136
137/* vim: set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 : */ 189/* vim: set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 : */