1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 ** === N O T E S ===========================================================
24 ** ========================================================================= */
26 /* === H E A D E R S ======================================================= */
37 #include <synfig/string.h>
38 #include <synfig/time.h>
39 #include <synfig/context.h>
40 #include <synfig/paramdesc.h>
41 #include <synfig/renddesc.h>
42 #include <synfig/surface.h>
43 #include <synfig/value.h>
44 #include <synfig/valuenode.h>
48 /* === M A C R O S ========================================================= */
50 #define LOG_OF_2 0.69314718055994528623
52 /* === G L O B A L S ======================================================= */
54 SYNFIG_LAYER_INIT(Julia);
55 SYNFIG_LAYER_SET_NAME(Julia,"julia");
56 SYNFIG_LAYER_SET_LOCAL_NAME(Julia,_("Julia Set"));
57 SYNFIG_LAYER_SET_CATEGORY(Julia,_("Fractals"));
58 SYNFIG_LAYER_SET_VERSION(Julia,"0.1");
59 SYNFIG_LAYER_SET_CVS_ID(Julia,"$Id$");
61 /* === P R O C E D U R E S ================================================= */
64 color_neg_flip(Color &color)
77 color.set_g(color.get_g()-color.get_r());
78 color.set_b(color.get_b()-color.get_r());
83 color.set_r(color.get_r()-color.get_g());
84 color.set_b(color.get_b()-color.get_g());
89 color.set_r(color.get_r()-color.get_b());
90 color.set_g(color.get_g()-color.get_b());
95 /* === M E T H O D S ======================================================= */
97 Julia::Julia():color_shift(angle::degrees(0))
99 icolor=Color::black();
100 ocolor=Color::black();
102 color_shift=Angle::deg(0);
105 distort_outside=true;
111 invert_outside=false;
120 lp=log(log(bailout));
124 Julia::set_param(const String & param, const ValueBase &value)
132 IMPORT(distort_inside);
133 IMPORT(distort_outside);
134 IMPORT(shade_inside);
135 IMPORT(shade_outside);
136 IMPORT(solid_inside);
137 IMPORT(solid_outside);
138 IMPORT(invert_inside);
139 IMPORT(invert_outside);
140 IMPORT(color_inside);
141 IMPORT(color_outside);
144 IMPORT(smooth_outside);
147 if(param=="iterations" && value.same_type_as(iterations))
149 iterations=value.get(iterations);
152 if(iterations>500000)
156 if(param=="bailout" && value.same_type_as(bailout))
158 bailout=value.get(bailout);
160 lp=log(log(bailout));
168 Julia::get_param(const String & param)const
176 EXPORT(distort_inside);
177 EXPORT(distort_outside);
178 EXPORT(shade_inside);
179 EXPORT(shade_outside);
180 EXPORT(solid_inside);
181 EXPORT(solid_outside);
182 EXPORT(invert_inside);
183 EXPORT(invert_outside);
184 EXPORT(color_inside);
185 EXPORT(color_outside);
187 EXPORT(smooth_outside);
191 return sqrt(bailout);
200 Julia::get_color(Context context, const Point &pos)const
218 for(int i=0;i<iterations;i++)
220 // Perform complex multiplication
223 zi=zr_hold*zi*2 + ci;
225 // Use "broken" algorithm, if requested (looks weird)
228 // Calculate Magnitude
235 // Darco's original mandelbrot smoothing algo
236 // depth=((Point::value_type)i+(2.0-sqrt(mag))/PI);
238 // Linas Vepstas algo (Better than darco's)
239 // See (http://linas.org/art-gallery/escape/smooth.html)
240 depth= (ColorReal)i - log(log(sqrt(mag))) / LOG_OF_2;
246 depth=static_cast<ColorReal>(i);
252 ret=context.get_color(Point(zr,zi));
254 ret=context.get_color(pos);
260 ret=ret.set_uv(zr,zi).clamped_negative();
263 ret=ret.rotate_uv(color_shift.operator*(depth)).clamped_negative();
267 ColorReal alpha=depth/static_cast<ColorReal>(iterations);
268 ret=(ocolor-ret)*alpha+ret;
278 ret=context.get_color(Point(zr,zi));
280 ret=context.get_color(pos);
286 ret=ret.set_uv(zr,zi).clamped_negative();
289 ret=(icolor-ret)*mag+ret;
295 Julia::get_param_vocab()const
299 ret.push_back(ParamDesc("icolor")
300 .set_local_name(_("Inside Color"))
301 .set_description(_("Color of the Set"))
303 ret.push_back(ParamDesc("ocolor")
304 .set_local_name(_("Outside Color"))
305 .set_description(_("Color outside the Set"))
307 ret.push_back(ParamDesc("color_shift")
308 .set_local_name(_("Color Shift"))
310 ret.push_back(ParamDesc("iterations")
311 .set_local_name(_("Iterations"))
313 ret.push_back(ParamDesc("seed")
314 .set_local_name(_("Seed Point"))
316 ret.push_back(ParamDesc("bailout")
317 .set_local_name(_("Bailout ValueBase"))
320 ret.push_back(ParamDesc("distort_inside")
321 .set_local_name(_("Distort Inside"))
323 ret.push_back(ParamDesc("shade_inside")
324 .set_local_name(_("Shade Inside"))
326 ret.push_back(ParamDesc("solid_inside")
327 .set_local_name(_("Solid Inside"))
329 ret.push_back(ParamDesc("invert_inside")
330 .set_local_name(_("Invert Inside"))
332 ret.push_back(ParamDesc("color_inside")
333 .set_local_name(_("Color Inside"))
335 ret.push_back(ParamDesc("distort_outside")
336 .set_local_name(_("Distort Outside"))
338 ret.push_back(ParamDesc("shade_outside")
339 .set_local_name(_("Shade Outside"))
341 ret.push_back(ParamDesc("solid_outside")
342 .set_local_name(_("Solid Outside"))
344 ret.push_back(ParamDesc("invert_outside")
345 .set_local_name(_("Invert Outside"))
347 ret.push_back(ParamDesc("color_outside")
348 .set_local_name(_("Color Outside"))
351 ret.push_back(ParamDesc("color_cycle")
352 .set_local_name(_("Color Cycle"))
354 ret.push_back(ParamDesc("smooth_outside")
355 .set_local_name(_("Smooth Outside"))
356 .set_description(_("Smooth the coloration outside the set"))
358 ret.push_back(ParamDesc("broken")
359 .set_local_name(_("Break Set"))
360 .set_description(_("Modify equation to achieve interesting results"))