1 /* === S Y N F I G ========================================================= */
3 ** \brief Implementation of the "Julia Set" layer
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,N_("Julia Set"));
57 SYNFIG_LAYER_SET_CATEGORY(Julia,N_("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));
121 Layer::Vocab voc(get_param_vocab());
122 Layer::fill_static(voc);
126 Julia::set_param(const String & param, const ValueBase &value)
134 IMPORT(distort_inside);
135 IMPORT(distort_outside);
136 IMPORT(shade_inside);
137 IMPORT(shade_outside);
138 IMPORT(solid_inside);
139 IMPORT(solid_outside);
140 IMPORT(invert_inside);
141 IMPORT(invert_outside);
142 IMPORT(color_inside);
143 IMPORT(color_outside);
146 IMPORT(smooth_outside);
149 // TODO: Use IMPORT_PLUS
150 if(param=="iterations" && value.same_type_as(iterations))
152 iterations=value.get(iterations);
155 if(iterations>500000)
157 set_param_static(param, value.get_static());
160 if(param=="bailout" && value.same_type_as(bailout))
162 bailout=value.get(bailout);
164 lp=log(log(bailout));
165 set_param_static(param, value.get_static());
173 Julia::get_param(const String & param)const
181 EXPORT(distort_inside);
182 EXPORT(distort_outside);
183 EXPORT(shade_inside);
184 EXPORT(shade_outside);
185 EXPORT(solid_inside);
186 EXPORT(solid_outside);
187 EXPORT(invert_inside);
188 EXPORT(invert_outside);
189 EXPORT(color_inside);
190 EXPORT(color_outside);
192 EXPORT(smooth_outside);
197 ValueBase ret(sqrt(bailout));
198 ret.set_static(get_param_static(param));
209 Julia::get_color(Context context, const Point &pos)const
227 for(int i=0;i<iterations;i++)
229 // Perform complex multiplication
232 zi=zr_hold*zi*2 + ci;
234 // Use "broken" algorithm, if requested (looks weird)
237 // Calculate Magnitude
244 // Darco's original mandelbrot smoothing algo
245 // depth=((Point::value_type)i+(2.0-sqrt(mag))/PI);
247 // Linas Vepstas algo (Better than darco's)
248 // See (http://linas.org/art-gallery/escape/smooth.html)
249 depth= (ColorReal)i - log(log(sqrt(mag))) / LOG_OF_2;
255 depth=static_cast<ColorReal>(i);
261 ret=context.get_color(Point(zr,zi));
263 ret=context.get_color(pos);
269 ret=ret.set_uv(zr,zi).clamped_negative();
272 ret=ret.rotate_uv(color_shift.operator*(depth)).clamped_negative();
276 ColorReal alpha=depth/static_cast<ColorReal>(iterations);
277 ret=(ocolor-ret)*alpha+ret;
287 ret=context.get_color(Point(zr,zi));
289 ret=context.get_color(pos);
295 ret=ret.set_uv(zr,zi).clamped_negative();
298 ret=(icolor-ret)*mag+ret;
304 Julia::get_param_vocab()const
308 ret.push_back(ParamDesc("icolor")
309 .set_local_name(_("Inside Color"))
310 .set_description(_("Color of the Set"))
312 ret.push_back(ParamDesc("ocolor")
313 .set_local_name(_("Outside Color"))
314 .set_description(_("Color outside the Set"))
316 ret.push_back(ParamDesc("color_shift")
317 .set_local_name(_("Color Shift"))
319 ret.push_back(ParamDesc("iterations")
320 .set_local_name(_("Iterations"))
322 ret.push_back(ParamDesc("seed")
323 .set_local_name(_("Seed Point"))
325 ret.push_back(ParamDesc("bailout")
326 .set_local_name(_("Bailout ValueBase"))
329 ret.push_back(ParamDesc("distort_inside")
330 .set_local_name(_("Distort Inside"))
332 ret.push_back(ParamDesc("shade_inside")
333 .set_local_name(_("Shade Inside"))
335 ret.push_back(ParamDesc("solid_inside")
336 .set_local_name(_("Solid Inside"))
338 ret.push_back(ParamDesc("invert_inside")
339 .set_local_name(_("Invert Inside"))
341 ret.push_back(ParamDesc("color_inside")
342 .set_local_name(_("Color Inside"))
344 ret.push_back(ParamDesc("distort_outside")
345 .set_local_name(_("Distort Outside"))
347 ret.push_back(ParamDesc("shade_outside")
348 .set_local_name(_("Shade Outside"))
350 ret.push_back(ParamDesc("solid_outside")
351 .set_local_name(_("Solid Outside"))
353 ret.push_back(ParamDesc("invert_outside")
354 .set_local_name(_("Invert Outside"))
356 ret.push_back(ParamDesc("color_outside")
357 .set_local_name(_("Color Outside"))
360 ret.push_back(ParamDesc("color_cycle")
361 .set_local_name(_("Color Cycle"))
363 ret.push_back(ParamDesc("smooth_outside")
364 .set_local_name(_("Smooth Outside"))
365 .set_description(_("Smooth the coloration outside the set"))
367 ret.push_back(ParamDesc("broken")
368 .set_local_name(_("Break Set"))
369 .set_description(_("Modify equation to achieve interesting results"))