1 /*! ========================================================================
4 ** $Id: julia.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This software and associated documentation
9 ** are CONFIDENTIAL and PROPRIETARY property of
10 ** the above-mentioned copyright holder.
12 ** You may not copy, print, publish, or in any
13 ** other way distribute this software without
14 ** a prior written agreement with
15 ** the copyright holder.
17 ** === N O T E S ===========================================================
19 ** ========================================================================= */
21 /* === H E A D E R S ======================================================= */
32 #include <synfig/string.h>
33 #include <synfig/time.h>
34 #include <synfig/context.h>
35 #include <synfig/paramdesc.h>
36 #include <synfig/renddesc.h>
37 #include <synfig/surface.h>
38 #include <synfig/value.h>
39 #include <synfig/valuenode.h>
43 /* === M A C R O S ========================================================= */
45 #define LOG_OF_2 0.69314718055994528623
47 /* === G L O B A L S ======================================================= */
49 SYNFIG_LAYER_INIT(Julia);
50 SYNFIG_LAYER_SET_NAME(Julia,"julia");
51 SYNFIG_LAYER_SET_LOCAL_NAME(Julia,_("Julia Set"));
52 SYNFIG_LAYER_SET_CATEGORY(Julia,_("Fractals"));
53 SYNFIG_LAYER_SET_VERSION(Julia,"0.1");
54 SYNFIG_LAYER_SET_CVS_ID(Julia,"$Id: julia.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
56 /* === P R O C E D U R E S ================================================= */
59 color_neg_flip(Color &color)
72 color.set_g(color.get_g()-color.get_r());
73 color.set_b(color.get_b()-color.get_r());
78 color.set_r(color.get_r()-color.get_g());
79 color.set_b(color.get_b()-color.get_g());
84 color.set_r(color.get_r()-color.get_b());
85 color.set_g(color.get_g()-color.get_b());
90 /* === M E T H O D S ======================================================= */
92 Julia::Julia():color_shift(angle::degrees(0))
94 icolor=Color::black();
95 ocolor=Color::black();
97 color_shift=Angle::deg(0);
100 distort_outside=true;
106 invert_outside=false;
115 lp=log(log(bailout));
119 Julia::set_param(const String & param, const ValueBase &value)
127 IMPORT(distort_inside);
128 IMPORT(distort_outside);
129 IMPORT(shade_inside);
130 IMPORT(shade_outside);
131 IMPORT(solid_inside);
132 IMPORT(solid_outside);
133 IMPORT(invert_inside);
134 IMPORT(invert_outside);
135 IMPORT(color_inside);
136 IMPORT(color_outside);
139 IMPORT(smooth_outside);
142 if(param=="iterations" && value.same_as(iterations))
144 iterations=value.get(iterations);
147 if(iterations>500000)
151 if(param=="bailout" && value.same_as(bailout))
153 bailout=value.get(bailout);
155 lp=log(log(bailout));
163 Julia::get_param(const String & param)const
171 EXPORT(distort_inside);
172 EXPORT(distort_outside);
173 EXPORT(shade_inside);
174 EXPORT(shade_outside);
175 EXPORT(solid_inside);
176 EXPORT(solid_outside);
177 EXPORT(invert_inside);
178 EXPORT(invert_outside);
179 EXPORT(color_inside);
180 EXPORT(color_outside);
182 EXPORT(smooth_outside);
186 return sqrt(bailout);
195 Julia::get_color(Context context, const Point &pos)const
213 for(int i=0;i<iterations;i++)
215 // Perform complex multiplication
218 zi=zr_hold*zi*2 + ci;
220 // Use "broken" algorithm, if requested (looks weird)
223 // Calculate Magnitude
230 // Darco's original mandelbrot smoothing algo
231 // depth=((Point::value_type)i+(2.0-sqrt(mag))/PI);
233 // Linas Vepstas algo (Better than darco's)
234 // See (http://linas.org/art-gallery/escape/smooth.html)
235 depth= (ColorReal)i - log(log(sqrt(mag))) / LOG_OF_2;
241 depth=static_cast<ColorReal>(i);
247 ret=context.get_color(Point(zr,zi));
249 ret=context.get_color(pos);
255 ret=ret.set_uv(zr,zi).clamped_negative();
258 ret=ret.rotate_uv(color_shift.operator*(depth)).clamped_negative();
262 ColorReal alpha=depth/static_cast<ColorReal>(iterations);
263 ret=(ocolor-ret)*alpha+ret;
273 ret=context.get_color(Point(zr,zi));
275 ret=context.get_color(pos);
281 ret=ret.set_uv(zr,zi).clamped_negative();
284 ret=(icolor-ret)*mag+ret;
290 Julia::get_param_vocab()const
294 ret.push_back(ParamDesc("icolor")
295 .set_local_name(_("Inside Color"))
296 .set_description(_("Color of the Set"))
298 ret.push_back(ParamDesc("ocolor")
299 .set_local_name(_("Outside Color"))
300 .set_description(_("Color outside the Set"))
302 ret.push_back(ParamDesc("color_shift")
303 .set_local_name(_("Color Shift"))
305 ret.push_back(ParamDesc("iterations")
306 .set_local_name(_("Iterations"))
308 ret.push_back(ParamDesc("seed")
309 .set_local_name(_("Seed Point"))
311 ret.push_back(ParamDesc("bailout")
312 .set_local_name(_("Bailout ValueBase"))
315 ret.push_back(ParamDesc("distort_inside")
316 .set_local_name(_("Distort Inside"))
318 ret.push_back(ParamDesc("shade_inside")
319 .set_local_name(_("Shade Inside"))
321 ret.push_back(ParamDesc("solid_inside")
322 .set_local_name(_("Solid Inside"))
324 ret.push_back(ParamDesc("invert_inside")
325 .set_local_name(_("Invert Inside"))
327 ret.push_back(ParamDesc("color_inside")
328 .set_local_name(_("Color Inside"))
330 ret.push_back(ParamDesc("distort_outside")
331 .set_local_name(_("Distort Outside"))
333 ret.push_back(ParamDesc("shade_outside")
334 .set_local_name(_("Shade Outside"))
336 ret.push_back(ParamDesc("solid_outside")
337 .set_local_name(_("Solid Outside"))
339 ret.push_back(ParamDesc("invert_outside")
340 .set_local_name(_("Invert Outside"))
342 ret.push_back(ParamDesc("color_outside")
343 .set_local_name(_("Color Outside"))
346 ret.push_back(ParamDesc("color_cycle")
347 .set_local_name(_("Color Cycle"))
349 ret.push_back(ParamDesc("smooth_outside")
350 .set_local_name(_("Smooth Outside"))
351 .set_description(_("Smooth the coloration outside the set"))
353 ret.push_back(ParamDesc("broken")
354 .set_local_name(_("Break Set"))
355 .set_description(_("Modify equation to achieve interesting results"))