1 /*! ========================================================================
4 ** $Id: julia.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
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.
18 ** === N O T E S ===========================================================
20 ** ========================================================================= */
22 /* === H E A D E R S ======================================================= */
33 #include <synfig/string.h>
34 #include <synfig/time.h>
35 #include <synfig/context.h>
36 #include <synfig/paramdesc.h>
37 #include <synfig/renddesc.h>
38 #include <synfig/surface.h>
39 #include <synfig/value.h>
40 #include <synfig/valuenode.h>
44 /* === M A C R O S ========================================================= */
46 #define LOG_OF_2 0.69314718055994528623
48 /* === G L O B A L S ======================================================= */
50 SYNFIG_LAYER_INIT(Julia);
51 SYNFIG_LAYER_SET_NAME(Julia,"julia");
52 SYNFIG_LAYER_SET_LOCAL_NAME(Julia,_("Julia Set"));
53 SYNFIG_LAYER_SET_CATEGORY(Julia,_("Fractals"));
54 SYNFIG_LAYER_SET_VERSION(Julia,"0.1");
55 SYNFIG_LAYER_SET_CVS_ID(Julia,"$Id: julia.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
57 /* === P R O C E D U R E S ================================================= */
60 color_neg_flip(Color &color)
73 color.set_g(color.get_g()-color.get_r());
74 color.set_b(color.get_b()-color.get_r());
79 color.set_r(color.get_r()-color.get_g());
80 color.set_b(color.get_b()-color.get_g());
85 color.set_r(color.get_r()-color.get_b());
86 color.set_g(color.get_g()-color.get_b());
91 /* === M E T H O D S ======================================================= */
93 Julia::Julia():color_shift(angle::degrees(0))
95 icolor=Color::black();
96 ocolor=Color::black();
98 color_shift=Angle::deg(0);
101 distort_outside=true;
107 invert_outside=false;
116 lp=log(log(bailout));
120 Julia::set_param(const String & param, const ValueBase &value)
128 IMPORT(distort_inside);
129 IMPORT(distort_outside);
130 IMPORT(shade_inside);
131 IMPORT(shade_outside);
132 IMPORT(solid_inside);
133 IMPORT(solid_outside);
134 IMPORT(invert_inside);
135 IMPORT(invert_outside);
136 IMPORT(color_inside);
137 IMPORT(color_outside);
140 IMPORT(smooth_outside);
143 if(param=="iterations" && value.same_as(iterations))
145 iterations=value.get(iterations);
148 if(iterations>500000)
152 if(param=="bailout" && value.same_as(bailout))
154 bailout=value.get(bailout);
156 lp=log(log(bailout));
164 Julia::get_param(const String & param)const
172 EXPORT(distort_inside);
173 EXPORT(distort_outside);
174 EXPORT(shade_inside);
175 EXPORT(shade_outside);
176 EXPORT(solid_inside);
177 EXPORT(solid_outside);
178 EXPORT(invert_inside);
179 EXPORT(invert_outside);
180 EXPORT(color_inside);
181 EXPORT(color_outside);
183 EXPORT(smooth_outside);
187 return sqrt(bailout);
196 Julia::get_color(Context context, const Point &pos)const
214 for(int i=0;i<iterations;i++)
216 // Perform complex multiplication
219 zi=zr_hold*zi*2 + ci;
221 // Use "broken" algorithm, if requested (looks weird)
224 // Calculate Magnitude
231 // Darco's original mandelbrot smoothing algo
232 // depth=((Point::value_type)i+(2.0-sqrt(mag))/PI);
234 // Linas Vepstas algo (Better than darco's)
235 // See (http://linas.org/art-gallery/escape/smooth.html)
236 depth= (ColorReal)i - log(log(sqrt(mag))) / LOG_OF_2;
242 depth=static_cast<ColorReal>(i);
248 ret=context.get_color(Point(zr,zi));
250 ret=context.get_color(pos);
256 ret=ret.set_uv(zr,zi).clamped_negative();
259 ret=ret.rotate_uv(color_shift.operator*(depth)).clamped_negative();
263 ColorReal alpha=depth/static_cast<ColorReal>(iterations);
264 ret=(ocolor-ret)*alpha+ret;
274 ret=context.get_color(Point(zr,zi));
276 ret=context.get_color(pos);
282 ret=ret.set_uv(zr,zi).clamped_negative();
285 ret=(icolor-ret)*mag+ret;
291 Julia::get_param_vocab()const
295 ret.push_back(ParamDesc("icolor")
296 .set_local_name(_("Inside Color"))
297 .set_description(_("Color of the Set"))
299 ret.push_back(ParamDesc("ocolor")
300 .set_local_name(_("Outside Color"))
301 .set_description(_("Color outside the Set"))
303 ret.push_back(ParamDesc("color_shift")
304 .set_local_name(_("Color Shift"))
306 ret.push_back(ParamDesc("iterations")
307 .set_local_name(_("Iterations"))
309 ret.push_back(ParamDesc("seed")
310 .set_local_name(_("Seed Point"))
312 ret.push_back(ParamDesc("bailout")
313 .set_local_name(_("Bailout ValueBase"))
316 ret.push_back(ParamDesc("distort_inside")
317 .set_local_name(_("Distort Inside"))
319 ret.push_back(ParamDesc("shade_inside")
320 .set_local_name(_("Shade Inside"))
322 ret.push_back(ParamDesc("solid_inside")
323 .set_local_name(_("Solid Inside"))
325 ret.push_back(ParamDesc("invert_inside")
326 .set_local_name(_("Invert Inside"))
328 ret.push_back(ParamDesc("color_inside")
329 .set_local_name(_("Color Inside"))
331 ret.push_back(ParamDesc("distort_outside")
332 .set_local_name(_("Distort Outside"))
334 ret.push_back(ParamDesc("shade_outside")
335 .set_local_name(_("Shade Outside"))
337 ret.push_back(ParamDesc("solid_outside")
338 .set_local_name(_("Solid Outside"))
340 ret.push_back(ParamDesc("invert_outside")
341 .set_local_name(_("Invert Outside"))
343 ret.push_back(ParamDesc("color_outside")
344 .set_local_name(_("Color Outside"))
347 ret.push_back(ParamDesc("color_cycle")
348 .set_local_name(_("Color Cycle"))
350 ret.push_back(ParamDesc("smooth_outside")
351 .set_local_name(_("Smooth Outside"))
352 .set_description(_("Smooth the coloration outside the set"))
354 ret.push_back(ParamDesc("broken")
355 .set_local_name(_("Break Set"))
356 .set_description(_("Modify equation to achieve interesting results"))