1 /**
2  * Mandelbulber v2, a 3D fractal generator  _%}}i*<.         ______
3  * Copyright (C) 2020 Mandelbulber Team   _>]|=||i=i<,      / ____/ __    __
4  *                                        \><||i|=>>%)     / /   __/ /___/ /_
5  * This file is part of Mandelbulber.     )<=i=]=|=i<>    / /__ /_  __/_  __/
6  * The project is licensed under GPLv3,   -<>>=|><|||`    \____/ /_/   /_/
7  * see also COPYING file in this folder.    ~+{i%+++
8  *
9  * Msltoe Donut formula
10  * @reference
11  * http://www.fractalforums.com/new-theories-and-research/
12  * low-hanging-dessert-an-escape-time-donut-fractal/msg90171/#msg90171
13  */
14 
15 #include "all_fractal_definitions.h"
16 
cFractalMsltoeDonut()17 cFractalMsltoeDonut::cFractalMsltoeDonut() : cAbstractFractal()
18 {
19 	nameInComboBox = "Msltoe - Donut";
20 	internalName = "msltoe_donut";
21 	internalID = fractal::msltoeDonut;
22 	DEType = deltaDEType;
23 	DEFunctionType = linearDEFunction;
24 	cpixelAddition = cpixelDisabledByDefault;
25 	defaultBailout = 4.0;
26 	DEAnalyticFunction = analyticFunctionNone;
27 	coloringFunction = coloringFunctionDonut;
28 }
29 
FormulaCode(CVector4 & z,const sFractal * fractal,sExtendedAux & aux)30 void cFractalMsltoeDonut::FormulaCode(CVector4 &z, const sFractal *fractal, sExtendedAux &aux)
31 {
32 	double radius2 = fractal->donut.ringThickness;
33 	double nSect = M_PI_2x / fractal->donut.number;
34 	double fact = fractal->donut.factor;
35 
36 	double R = sqrt(z.x * z.x + z.y * z.y);
37 	double R2 = fractal->donut.ringRadius - R;
38 	double t = R2 * R2 + z.z * z.z - radius2 * radius2;
39 
40 	double theta = atan2(z.y, z.x);
41 	double theta2 = nSect * round(theta / nSect);
42 
43 	if (t > 0.03)
44 	{
45 		double c1 = cos(theta2);
46 		double s1 = sin(theta2);
47 
48 		double x1 = c1 * z.x + s1 * z.y;
49 		double y1 = -s1 * z.x + c1 * z.y;
50 		double z1 = z.z;
51 
52 		x1 = x1 - fractal->donut.ringRadius;
53 
54 		z.x = fact * x1;
55 		z.y = fact * z1;
56 		z.z = fact * y1;
57 	}
58 	else
59 	{
60 		z /= t;
61 	}
62 	aux.color += theta2;
63 }
64