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  * Vicsek
10  */
11 
12 #include "all_fractal_definitions.h"
13 
cFractalVicsek()14 cFractalVicsek::cFractalVicsek() : cAbstractFractal()
15 {
16 	nameInComboBox = "Vicsek";
17 	internalName = "vicsek";
18 	internalID = fractal::vicsek;
19 	DEType = analyticDEType;
20 	DEFunctionType = linearDEFunction;
21 	cpixelAddition = cpixelDisabledByDefault;
22 	defaultBailout = 10.0;
23 	DEAnalyticFunction = analyticFunctionIFS;
24 	coloringFunction = coloringFunctionIFS;
25 }
26 
FormulaCode(CVector4 & z,const sFractal * fractal,sExtendedAux & aux)27 void cFractalVicsek::FormulaCode(CVector4 &z, const sFractal *fractal, sExtendedAux &aux)
28 {
29 	double colorAdd = 0.0;
30 	double rrCol = 0.0;
31 	CVector4 zCol = z;
32 	CVector4 oldZ = z;
33 
34 	// octo
35 	if (fractal->transformCommon.functionEnabledxFalse
36 			&& aux.i >= fractal->transformCommon.startIterationsE
37 			&& aux.i < fractal->transformCommon.stopIterationsE)
38 	{
39 		if (z.x + z.y < 0.0) z = CVector4(-z.y, -z.x, z.z, z.w);
40 
41 		if (z.x + z.z < 0.0) // z.xz = -z.zx;
42 			z = CVector4(-z.z, z.y, -z.x, z.w);
43 
44 		if (z.x - z.y < 0.0) // z.xy = z.yx;
45 			z = CVector4(z.y, z.x, z.z, z.w);
46 
47 		if (z.x - z.z < 0.0) // z.xz = z.zx;
48 			z = CVector4(z.z, z.y, z.x, z.w);
49 
50 		z.x = fabs(z.x);
51 		z = z * fractal->transformCommon.scale2
52 				- fractal->transformCommon.offset100 * (fractal->transformCommon.scale2 - 1.0);
53 
54 		aux.DE *= fractal->transformCommon.scale2;
55 	}
56 
57 	// spherical fold
58 	if (fractal->transformCommon.functionEnabledSFalse
59 			&& aux.i >= fractal->transformCommon.startIterationsS
60 			&& aux.i < fractal->transformCommon.stopIterationsS)
61 	{
62 		double rr = z.Dot(z);
63 		rrCol = rr; // test ooooooooooooooooooooooooooooooooo
64 		// if (r2 < 1e-21) r2 = 1e-21;
65 		if (rr < fractal->transformCommon.minR2p25)
66 		{
67 			double tglad_factor1 = fractal->transformCommon.maxMinR2factor;
68 			// double tglad_factor1 = fractal->transformCommon.maxR2d1 /fractal->transformCommon.minR2p25;
69 			z *= tglad_factor1;
70 			aux.DE *= tglad_factor1;
71 			aux.color += fractal->mandelbox.color.factorSp1;
72 		}
73 		else if (rr < fractal->transformCommon.maxR2d1)
74 		{
75 			double tglad_factor2 = fractal->transformCommon.maxR2d1 / rr;
76 			z *= tglad_factor2;
77 			aux.DE *= tglad_factor2;
78 			aux.color += fractal->mandelbox.color.factorSp2;
79 		}
80 		z *= fractal->transformCommon.scale08;
81 		aux.DE = aux.DE * fabs(fractal->transformCommon.scale08);
82 	}
83 
84 	// Vicsek
85 	if (fractal->transformCommon.functionEnabledM
86 			&& aux.i >= fractal->transformCommon.startIterationsM
87 			&& aux.i < fractal->transformCommon.stopIterationsM)
88 	{
89 		zCol = z; // test ooooooooooooooooooooooooooooooooo
90 		z = fabs(z);
91 		if (z.x - z.y < 0.0) swap(z.y, z.x);
92 		if (z.x - z.z < 0.0) swap(z.z, z.x);
93 		if (z.y - z.z < 0.0) swap(z.z, z.y);
94 		z *= fractal->transformCommon.scale3;
95 		aux.DE *= fractal->transformCommon.scale3;
96 
97 		CVector4 limit = fractal->transformCommon.offset111;
98 		if (z.x > limit.x * 0.5) z.x -= limit.x * fractal->transformCommon.scaleA1;
99 		if (z.y > limit.y * 0.5) z.y -= limit.y;
100 		if (z.z > limit.z) z.z -= 2.0 * limit.z;
101 		z.x += fractal->transformCommon.offset0;
102 		zCol = z; // test ooooooooooooooooooooooooooooooooo
103 	}
104 
105 	// 45 rot XY
106 	if (fractal->transformCommon.functionEnabledXFalse
107 			&& aux.i >= fractal->transformCommon.startIterations
108 			&& aux.i < fractal->transformCommon.stopIterations)
109 	{
110 		double xTemp = SQRT_1_2 * (z.x - z.y);
111 		z.y = SQRT_1_2 * (z.y + z.x);
112 		z.x = xTemp;
113 	}
114 
115 	// iter weight
116 	if (fractal->transformCommon.functionEnabledFalse)
117 	{
118 		CVector4 zA = (aux.i == fractal->transformCommon.intA) ? z : CVector4();
119 		CVector4 zB = (aux.i == fractal->transformCommon.intB) ? z : CVector4();
120 
121 		z = (z * fractal->transformCommon.scale1) + (zA * fractal->transformCommon.offsetA0)
122 				+ (zB * fractal->transformCommon.offsetB0);
123 		aux.DE *= fractal->transformCommon.scale1;
124 	}
125 
126 	// Analytic DE tweak
127 	if (fractal->analyticDE.enabledFalse)
128 		aux.DE = aux.DE * fractal->analyticDE.scale1 + fractal->analyticDE.offset0;
129 
130 	// aux color
131 	if (fractal->foldColor.auxColorEnabledFalse)
132 	{
133 		if (fractal->transformCommon.functionEnabledCxFalse)
134 		{
135 			if (zCol.x != oldZ.x)
136 				colorAdd += fractal->mandelbox.color.factor.x
137 										* (fabs(zCol.x) - fractal->transformCommon.additionConstant111.x);
138 			if (zCol.y != oldZ.y)
139 				colorAdd += fractal->mandelbox.color.factor.y
140 										* (fabs(zCol.y) - fractal->transformCommon.additionConstant111.y);
141 			if (zCol.z != oldZ.z)
142 				colorAdd += fractal->mandelbox.color.factor.z
143 										* (fabs(zCol.z) - fractal->transformCommon.additionConstant111.z);
144 
145 			if (rrCol < fractal->transformCommon.maxR2d1)
146 			{
147 				if (rrCol < fractal->transformCommon.minR2p25)
148 					colorAdd +=
149 						fractal->mandelbox.color.factorSp1 * (fractal->transformCommon.minR2p25 - rrCol)
150 						+ fractal->mandelbox.color.factorSp2
151 								* (fractal->transformCommon.maxR2d1 - fractal->transformCommon.minR2p25);
152 				else
153 					colorAdd +=
154 						fractal->mandelbox.color.factorSp2 * (fractal->transformCommon.maxR2d1 - rrCol);
155 			}
156 		}
157 		else
158 		{
159 			if (zCol.x != oldZ.x) colorAdd += fractal->mandelbox.color.factor.x;
160 			if (zCol.y != oldZ.y) colorAdd += fractal->mandelbox.color.factor.y;
161 			if (zCol.z != oldZ.z) colorAdd += fractal->mandelbox.color.factor.z;
162 
163 			if (rrCol < fractal->transformCommon.minR2p25)
164 				colorAdd += fractal->mandelbox.color.factorSp1;
165 			else if (rrCol < fractal->transformCommon.maxR2d1)
166 				colorAdd += fractal->mandelbox.color.factorSp2;
167 		}
168 		aux.color += colorAdd;
169 	}
170 }
171