1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
6 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
19 ** === N O T E S ===========================================================
21 ** ========================================================================= */
23 /* === H E A D E R S ======================================================= */
34 #include <synfig/string.h>
35 #include <synfig/time.h>
36 #include <synfig/context.h>
37 #include <synfig/paramdesc.h>
38 #include <synfig/renddesc.h>
39 #include <synfig/surface.h>
40 #include <synfig/value.h>
41 #include <synfig/valuenode.h>
45 /* === M A C R O S ========================================================= */
47 #define LOG_OF_2 0.69314718055994528623
49 /* === G L O B A L S ======================================================= */
51 SYNFIG_LAYER_INIT(Julia);
52 SYNFIG_LAYER_SET_NAME(Julia,"julia");
53 SYNFIG_LAYER_SET_LOCAL_NAME(Julia,_("Julia Set"));
54 SYNFIG_LAYER_SET_CATEGORY(Julia,_("Fractals"));
55 SYNFIG_LAYER_SET_VERSION(Julia,"0.1");
56 SYNFIG_LAYER_SET_CVS_ID(Julia,"$Id: julia.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
58 /* === P R O C E D U R E S ================================================= */
61 color_neg_flip(Color &color)
74 color.set_g(color.get_g()-color.get_r());
75 color.set_b(color.get_b()-color.get_r());
80 color.set_r(color.get_r()-color.get_g());
81 color.set_b(color.get_b()-color.get_g());
86 color.set_r(color.get_r()-color.get_b());
87 color.set_g(color.get_g()-color.get_b());
92 /* === M E T H O D S ======================================================= */
94 Julia::Julia():color_shift(angle::degrees(0))
96 icolor=Color::black();
97 ocolor=Color::black();
99 color_shift=Angle::deg(0);
102 distort_outside=true;
108 invert_outside=false;
117 lp=log(log(bailout));
121 Julia::set_param(const String & param, const ValueBase &value)
129 IMPORT(distort_inside);
130 IMPORT(distort_outside);
131 IMPORT(shade_inside);
132 IMPORT(shade_outside);
133 IMPORT(solid_inside);
134 IMPORT(solid_outside);
135 IMPORT(invert_inside);
136 IMPORT(invert_outside);
137 IMPORT(color_inside);
138 IMPORT(color_outside);
141 IMPORT(smooth_outside);
144 if(param=="iterations" && value.same_as(iterations))
146 iterations=value.get(iterations);
149 if(iterations>500000)
153 if(param=="bailout" && value.same_as(bailout))
155 bailout=value.get(bailout);
157 lp=log(log(bailout));
165 Julia::get_param(const String & param)const
173 EXPORT(distort_inside);
174 EXPORT(distort_outside);
175 EXPORT(shade_inside);
176 EXPORT(shade_outside);
177 EXPORT(solid_inside);
178 EXPORT(solid_outside);
179 EXPORT(invert_inside);
180 EXPORT(invert_outside);
181 EXPORT(color_inside);
182 EXPORT(color_outside);
184 EXPORT(smooth_outside);
188 return sqrt(bailout);
197 Julia::get_color(Context context, const Point &pos)const
215 for(int i=0;i<iterations;i++)
217 // Perform complex multiplication
220 zi=zr_hold*zi*2 + ci;
222 // Use "broken" algorithm, if requested (looks weird)
225 // Calculate Magnitude
232 // Darco's original mandelbrot smoothing algo
233 // depth=((Point::value_type)i+(2.0-sqrt(mag))/PI);
235 // Linas Vepstas algo (Better than darco's)
236 // See (http://linas.org/art-gallery/escape/smooth.html)
237 depth= (ColorReal)i - log(log(sqrt(mag))) / LOG_OF_2;
243 depth=static_cast<ColorReal>(i);
249 ret=context.get_color(Point(zr,zi));
251 ret=context.get_color(pos);
257 ret=ret.set_uv(zr,zi).clamped_negative();
260 ret=ret.rotate_uv(color_shift.operator*(depth)).clamped_negative();
264 ColorReal alpha=depth/static_cast<ColorReal>(iterations);
265 ret=(ocolor-ret)*alpha+ret;
275 ret=context.get_color(Point(zr,zi));
277 ret=context.get_color(pos);
283 ret=ret.set_uv(zr,zi).clamped_negative();
286 ret=(icolor-ret)*mag+ret;
292 Julia::get_param_vocab()const
296 ret.push_back(ParamDesc("icolor")
297 .set_local_name(_("Inside Color"))
298 .set_description(_("Color of the Set"))
300 ret.push_back(ParamDesc("ocolor")
301 .set_local_name(_("Outside Color"))
302 .set_description(_("Color outside the Set"))
304 ret.push_back(ParamDesc("color_shift")
305 .set_local_name(_("Color Shift"))
307 ret.push_back(ParamDesc("iterations")
308 .set_local_name(_("Iterations"))
310 ret.push_back(ParamDesc("seed")
311 .set_local_name(_("Seed Point"))
313 ret.push_back(ParamDesc("bailout")
314 .set_local_name(_("Bailout ValueBase"))
317 ret.push_back(ParamDesc("distort_inside")
318 .set_local_name(_("Distort Inside"))
320 ret.push_back(ParamDesc("shade_inside")
321 .set_local_name(_("Shade Inside"))
323 ret.push_back(ParamDesc("solid_inside")
324 .set_local_name(_("Solid Inside"))
326 ret.push_back(ParamDesc("invert_inside")
327 .set_local_name(_("Invert Inside"))
329 ret.push_back(ParamDesc("color_inside")
330 .set_local_name(_("Color Inside"))
332 ret.push_back(ParamDesc("distort_outside")
333 .set_local_name(_("Distort Outside"))
335 ret.push_back(ParamDesc("shade_outside")
336 .set_local_name(_("Shade Outside"))
338 ret.push_back(ParamDesc("solid_outside")
339 .set_local_name(_("Solid Outside"))
341 ret.push_back(ParamDesc("invert_outside")
342 .set_local_name(_("Invert Outside"))
344 ret.push_back(ParamDesc("color_outside")
345 .set_local_name(_("Color Outside"))
348 ret.push_back(ParamDesc("color_cycle")
349 .set_local_name(_("Color Cycle"))
351 ret.push_back(ParamDesc("smooth_outside")
352 .set_local_name(_("Smooth Outside"))
353 .set_description(_("Smooth the coloration outside the set"))
355 ret.push_back(ParamDesc("broken")
356 .set_local_name(_("Break Set"))
357 .set_description(_("Modify equation to achieve interesting results"))