-/*! ========================================================================
-** Sinfg
-** Template File
-** $Id: mandelbrot.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
+/* === S Y N F I G ========================================================= */
+/*! \file mandelbrot.cpp
+** \brief Implementation of the "Mandelbrot Set" layer
**
-** Copyright (c) 2002 Robert B. Quattlebaum Jr.
+** $Id$
**
-** This software and associated documentation
-** are CONFIDENTIAL and PROPRIETARY property of
-** the above-mentioned copyright holder.
+** \legal
+** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+** Copyright (c) 2007 Chris Moore
**
-** You may not copy, print, publish, or in any
-** other way distribute this software without
-** a prior written agreement with
-** the copyright holder.
+** This package is free software; you can redistribute it and/or
+** modify it under the terms of the GNU General Public License as
+** published by the Free Software Foundation; either version 2 of
+** the License, or (at your option) any later version.
+**
+** This package is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** General Public License for more details.
+** \endlegal
**
** === N O T E S ===========================================================
**
#include "mandelbrot.h"
-#include <sinfg/string.h>
-#include <sinfg/time.h>
-#include <sinfg/context.h>
-#include <sinfg/paramdesc.h>
-#include <sinfg/renddesc.h>
-#include <sinfg/surface.h>
-#include <sinfg/value.h>
-#include <sinfg/valuenode.h>
+#include <synfig/string.h>
+#include <synfig/time.h>
+#include <synfig/context.h>
+#include <synfig/paramdesc.h>
+#include <synfig/renddesc.h>
+#include <synfig/surface.h>
+#include <synfig/value.h>
+#include <synfig/valuenode.h>
#endif
/* === G L O B A L S ======================================================= */
-SINFG_LAYER_INIT(Mandelbrot);
-SINFG_LAYER_SET_NAME(Mandelbrot,"mandelbrot");
-SINFG_LAYER_SET_LOCAL_NAME(Mandelbrot,_("Mandelbrot Set"));
-SINFG_LAYER_SET_CATEGORY(Mandelbrot,_("Fractals"));
-SINFG_LAYER_SET_VERSION(Mandelbrot,"0.2");
-SINFG_LAYER_SET_CVS_ID(Mandelbrot,"$Id: mandelbrot.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
+SYNFIG_LAYER_INIT(Mandelbrot);
+SYNFIG_LAYER_SET_NAME(Mandelbrot,"mandelbrot");
+SYNFIG_LAYER_SET_LOCAL_NAME(Mandelbrot,N_("Mandelbrot Set"));
+SYNFIG_LAYER_SET_CATEGORY(Mandelbrot,N_("Fractals"));
+SYNFIG_LAYER_SET_VERSION(Mandelbrot,"0.2");
+SYNFIG_LAYER_SET_CVS_ID(Mandelbrot,"$Id$");
/* === P R O C E D U R E S ================================================= */
smooth_outside=true;
broken=false;
-
+
bailout=4;
lp=log(log(bailout));
}
-
+
bool
Mandelbrot::set_param(const String & param, const ValueBase &value)
{
IMPORT(gradient_offset_outside);
IMPORT(gradient_loop_inside);
IMPORT(gradient_scale_outside);
-
+
IMPORT(distort_inside);
IMPORT(distort_outside);
IMPORT(solid_inside);
IMPORT(gradient_inside);
IMPORT(gradient_outside);
-
- if(param=="iterations" && value.same_as(iterations))
+
+ if(param=="iterations" && value.same_type_as(iterations))
{
iterations=value.get(iterations);
if(iterations<0)
iterations=500000;
return true;
}
- if(param=="bailout" && value.same_as(bailout))
+ if(param=="bailout" && value.same_type_as(bailout))
{
bailout=value.get(bailout);
bailout*=bailout;
EXPORT(gradient_inside);
EXPORT(gradient_outside);
-
+
if(param=="bailout")
return sqrt(bailout);
EXPORT_NAME();
EXPORT_VERSION();
-
- return ValueBase();
+
+ return ValueBase();
}
Layer::Vocab
Mandelbrot::get_param_vocab()const
{
Layer::Vocab ret;
-
-
+
+
ret.push_back(ParamDesc("iterations")
.set_local_name(_("Iterations"))
);
.set_description(_("Modify equation to achieve interesting results"))
);
-
+
ret.push_back(ParamDesc("distort_inside")
.set_local_name(_("Distort Inside"))
.set_group(_("Inside"))
.set_local_name(_("Scale Outside"))
.set_group(_("Outside"))
);
-
+
return ret;
}
cr, ci,
zr, zi,
zr_hold;
-
+
ColorReal
- depth, mag;
-
+ depth, mag(0);
+
Color
ret;
-
+
zr=zi=0;
cr=pos[0];
ci=pos[1];
-
+
for(int i=0;i<iterations;i++)
{
// Perform complex multiplication
if(broken)zr+=zi; // Use "broken" algorithm, if requested (looks weird)
zi=zr_hold*zi*2 + ci;
-
+
// Calculate Magnitude
mag=zr*zr+zi*zi;
if(mag>bailout)
- {
+ {
if(smooth_outside)
{
// Darco's original mandelbrot smoothing algo
ColorReal amount(depth/static_cast<ColorReal>(iterations));
amount=amount*gradient_scale_outside+gradient_offset_outside;
amount-=floor(amount);
-
+
if(solid_outside)
ret=gradient_outside(amount);
else
ret=context.get_color(Point(pos[0]+zr,pos[1]+zi));
else
ret=context.get_color(pos);
-
+
if(invert_outside)
ret=~ret;
ret=Color::blend(gradient_outside(amount), ret, 1.0);
}
-
+
return ret;
}
}
ret=context.get_color(Point(pos[0]+zr,pos[1]+zi));
else
ret=context.get_color(pos);
-
+
if(invert_inside)
ret=~ret;
if(shade_inside)
ret=Color::blend(gradient_inside(amount), ret, 1.0);
}
-
+
return ret;
}