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  * Gnarl deformation in 2D (from Mark Townsend), and Luca 2011
10  * @reference
11  * http://www.fractalforums.com/mandelbulb-3d/custom-formulas-and-transforms-release-t17106/
12  */
13 
14 #include "all_fractal_definitions.h"
15 
cFractalTransfGnarl()16 cFractalTransfGnarl::cFractalTransfGnarl() : cAbstractFractal()
17 {
18 	nameInComboBox = "T>Gnarl";
19 	internalName = "transf_gnarl";
20 	internalID = fractal::transfGnarl;
21 	DEType = analyticDEType;
22 	DEFunctionType = withoutDEFunction;
23 	cpixelAddition = cpixelDisabledByDefault;
24 	defaultBailout = 100.0;
25 	DEAnalyticFunction = analyticFunctionNone;
26 	coloringFunction = coloringFunctionDefault;
27 }
28 
FormulaCode(CVector4 & z,const sFractal * fractal,sExtendedAux & aux)29 void cFractalTransfGnarl::FormulaCode(CVector4 &z, const sFractal *fractal, sExtendedAux &aux)
30 {
31 	Q_UNUSED(aux);
32 	CVector4 oldZ = z;
33 	CVector4 tempZ = z;
34 	double Scale = fractal->transformCommon.scale1;
35 	double stepX = fractal->transformCommon.scale3D000.x; //-0.1;
36 	double stepY = fractal->transformCommon.scale3D000.y;
37 	double stepZ = fractal->transformCommon.scale3D000.z;
38 	double Alpha = fractal->transformCommon.rotation.x; // 2.0;
39 	double Beta = fractal->transformCommon.rotation.y;	//-4.0;
40 	double Gamma = fractal->transformCommon.rotation.z; //-0.1;
41 
42 	if (fractal->transformCommon.functionEnabledAx)
43 	{
44 		tempZ.x = z.x - stepX * sin(z.y + sin(Alpha * (z.y + sin(Beta * z.y))));
45 		tempZ.y = z.y - stepY * sin(z.x + sin(Alpha * (z.x + sin(Beta * z.x))));
46 		z = tempZ;
47 	}
48 
49 	if (fractal->transformCommon.functionEnabledAxFalse)
50 	{
51 		double xx = z.x * z.x;
52 		tempZ.x = z.x + stepX * (sin(Gamma * (z.y - xx) + sin(Alpha * (z.y + Beta * cos(z.y)))));
53 		tempZ.y = z.y + stepY * (sin(Gamma * (z.y + xx) - Alpha * sin(xx + Beta * cos(xx))));
54 		z = tempZ;
55 	}
56 
57 	if (fractal->transformCommon.functionEnabledAyFalse)
58 	{
59 		double xx = z.x * z.x;
60 		double yy = z.y * z.y;
61 		tempZ.y = xx + stepY * (sin(yy * sqrt(fabs(z.y)) - Alpha * sin((yy + sin(Beta * yy)))));
62 		tempZ.x = yy - stepX * (sin(xx * sqrt(fabs(xx)) + sin(Alpha * (xx + sin(Beta * xx)))));
63 		z = tempZ;
64 	}
65 
66 	if (fractal->transformCommon.functionEnabledAzFalse)
67 	{
68 		tempZ.x = z.x - stepX * sin(z.z + sin(Alpha * (z.z + sin(Beta * z.z))));
69 		tempZ.y = z.y - stepY * sin(z.x + sin(Alpha * (z.x + sin(Beta * z.x))));
70 		tempZ.z = (z.z - stepZ * sin(z.y + sin(Alpha * (z.y + sin(Beta * z.y))))) * Scale;
71 		z = tempZ;
72 	}
73 	z.x *= Scale;
74 	z.y *= Scale;
75 
76 	if (fractal->analyticDE.enabled)
77 	{
78 		if (!fractal->analyticDE.enabledFalse)
79 			aux.DE = aux.DE * fabs(Scale) * fractal->analyticDE.scale1 + fractal->analyticDE.offset0;
80 		else
81 		{
82 			double avgScale = z.Length() / oldZ.Length();
83 			aux.DE = aux.DE * avgScale * fractal->analyticDE.scale1 + fractal->analyticDE.offset0;
84 		}
85 	}
86 }
87