1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 ** === N O T E S ===========================================================
23 ** ========================================================================= */
25 /* === H E A D E R S ======================================================= */
36 #include <synfig/string.h>
37 #include <synfig/time.h>
38 #include <synfig/context.h>
39 #include <synfig/paramdesc.h>
40 #include <synfig/renddesc.h>
41 #include <synfig/surface.h>
42 #include <synfig/value.h>
43 #include <synfig/valuenode.h>
47 /* === M A C R O S ========================================================= */
49 #define LOG_OF_2 0.69314718055994528623
51 /* === G L O B A L S ======================================================= */
53 SYNFIG_LAYER_INIT(Julia);
54 SYNFIG_LAYER_SET_NAME(Julia,"julia");
55 SYNFIG_LAYER_SET_LOCAL_NAME(Julia,_("Julia Set"));
56 SYNFIG_LAYER_SET_CATEGORY(Julia,_("Fractals"));
57 SYNFIG_LAYER_SET_VERSION(Julia,"0.1");
58 SYNFIG_LAYER_SET_CVS_ID(Julia,"$Id$");
60 /* === P R O C E D U R E S ================================================= */
63 color_neg_flip(Color &color)
76 color.set_g(color.get_g()-color.get_r());
77 color.set_b(color.get_b()-color.get_r());
82 color.set_r(color.get_r()-color.get_g());
83 color.set_b(color.get_b()-color.get_g());
88 color.set_r(color.get_r()-color.get_b());
89 color.set_g(color.get_g()-color.get_b());
94 /* === M E T H O D S ======================================================= */
96 Julia::Julia():color_shift(angle::degrees(0))
98 icolor=Color::black();
99 ocolor=Color::black();
101 color_shift=Angle::deg(0);
104 distort_outside=true;
110 invert_outside=false;
119 lp=log(log(bailout));
123 Julia::set_param(const String & param, const ValueBase &value)
131 IMPORT(distort_inside);
132 IMPORT(distort_outside);
133 IMPORT(shade_inside);
134 IMPORT(shade_outside);
135 IMPORT(solid_inside);
136 IMPORT(solid_outside);
137 IMPORT(invert_inside);
138 IMPORT(invert_outside);
139 IMPORT(color_inside);
140 IMPORT(color_outside);
143 IMPORT(smooth_outside);
146 if(param=="iterations" && value.same_as(iterations))
148 iterations=value.get(iterations);
151 if(iterations>500000)
155 if(param=="bailout" && value.same_as(bailout))
157 bailout=value.get(bailout);
159 lp=log(log(bailout));
167 Julia::get_param(const String & param)const
175 EXPORT(distort_inside);
176 EXPORT(distort_outside);
177 EXPORT(shade_inside);
178 EXPORT(shade_outside);
179 EXPORT(solid_inside);
180 EXPORT(solid_outside);
181 EXPORT(invert_inside);
182 EXPORT(invert_outside);
183 EXPORT(color_inside);
184 EXPORT(color_outside);
186 EXPORT(smooth_outside);
190 return sqrt(bailout);
199 Julia::get_color(Context context, const Point &pos)const
217 for(int i=0;i<iterations;i++)
219 // Perform complex multiplication
222 zi=zr_hold*zi*2 + ci;
224 // Use "broken" algorithm, if requested (looks weird)
227 // Calculate Magnitude
234 // Darco's original mandelbrot smoothing algo
235 // depth=((Point::value_type)i+(2.0-sqrt(mag))/PI);
237 // Linas Vepstas algo (Better than darco's)
238 // See (http://linas.org/art-gallery/escape/smooth.html)
239 depth= (ColorReal)i - log(log(sqrt(mag))) / LOG_OF_2;
245 depth=static_cast<ColorReal>(i);
251 ret=context.get_color(Point(zr,zi));
253 ret=context.get_color(pos);
259 ret=ret.set_uv(zr,zi).clamped_negative();
262 ret=ret.rotate_uv(color_shift.operator*(depth)).clamped_negative();
266 ColorReal alpha=depth/static_cast<ColorReal>(iterations);
267 ret=(ocolor-ret)*alpha+ret;
277 ret=context.get_color(Point(zr,zi));
279 ret=context.get_color(pos);
285 ret=ret.set_uv(zr,zi).clamped_negative();
288 ret=(icolor-ret)*mag+ret;
294 Julia::get_param_vocab()const
298 ret.push_back(ParamDesc("icolor")
299 .set_local_name(_("Inside Color"))
300 .set_description(_("Color of the Set"))
302 ret.push_back(ParamDesc("ocolor")
303 .set_local_name(_("Outside Color"))
304 .set_description(_("Color outside the Set"))
306 ret.push_back(ParamDesc("color_shift")
307 .set_local_name(_("Color Shift"))
309 ret.push_back(ParamDesc("iterations")
310 .set_local_name(_("Iterations"))
312 ret.push_back(ParamDesc("seed")
313 .set_local_name(_("Seed Point"))
315 ret.push_back(ParamDesc("bailout")
316 .set_local_name(_("Bailout ValueBase"))
319 ret.push_back(ParamDesc("distort_inside")
320 .set_local_name(_("Distort Inside"))
322 ret.push_back(ParamDesc("shade_inside")
323 .set_local_name(_("Shade Inside"))
325 ret.push_back(ParamDesc("solid_inside")
326 .set_local_name(_("Solid Inside"))
328 ret.push_back(ParamDesc("invert_inside")
329 .set_local_name(_("Invert Inside"))
331 ret.push_back(ParamDesc("color_inside")
332 .set_local_name(_("Color Inside"))
334 ret.push_back(ParamDesc("distort_outside")
335 .set_local_name(_("Distort Outside"))
337 ret.push_back(ParamDesc("shade_outside")
338 .set_local_name(_("Shade Outside"))
340 ret.push_back(ParamDesc("solid_outside")
341 .set_local_name(_("Solid Outside"))
343 ret.push_back(ParamDesc("invert_outside")
344 .set_local_name(_("Invert Outside"))
346 ret.push_back(ParamDesc("color_outside")
347 .set_local_name(_("Color Outside"))
350 ret.push_back(ParamDesc("color_cycle")
351 .set_local_name(_("Color Cycle"))
353 ret.push_back(ParamDesc("smooth_outside")
354 .set_local_name(_("Smooth Outside"))
355 .set_description(_("Smooth the coloration outside the set"))
357 ret.push_back(ParamDesc("broken")
358 .set_local_name(_("Break Set"))
359 .set_description(_("Modify equation to achieve interesting results"))