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 * Menger Sponge formula modified by Mclarekin
10 * from code by Knighty
11 */
12
13 #include "all_fractal_definitions.h"
14
cFractalMengerMod1()15 cFractalMengerMod1::cFractalMengerMod1() : cAbstractFractal()
16 {
17 nameInComboBox = "Menger - Mod 1";
18 internalName = "menger_mod1";
19 internalID = fractal::mengerMod1;
20 DEType = analyticDEType;
21 DEFunctionType = linearDEFunction;
22 cpixelAddition = cpixelDisabledByDefault;
23 defaultBailout = 10.0;
24 DEAnalyticFunction = analyticFunctionIFS;
25 coloringFunction = coloringFunctionIFS;
26 }
27
FormulaCode(CVector4 & z,const sFractal * fractal,sExtendedAux & aux)28 void cFractalMengerMod1::FormulaCode(CVector4 &z, const sFractal *fractal, sExtendedAux &aux)
29 {
30 z = fabs(z);
31 if (z.x - z.y < 0.0) swap(z.y, z.x);
32 if (z.x - z.z < 0.0) swap(z.z, z.x);
33 if (z.y - z.z < 0.0) swap(z.z, z.y);
34 z *= fractal->transformCommon.scale3;
35 z.x -= 2.0 * fractal->transformCommon.constantMultiplier111.x;
36 z.y -= 2.0 * fractal->transformCommon.constantMultiplier111.y;
37 if (z.z > 1.0) z.z -= 2.0 * fractal->transformCommon.constantMultiplier111.z;
38
39 aux.DE *= fractal->transformCommon.scale3;
40
41 if (fractal->transformCommon.rotationEnabled && aux.i >= fractal->transformCommon.startIterations
42 && aux.i < fractal->transformCommon.stopIterations)
43 {
44 z = fractal->transformCommon.rotationMatrix.RotateVector(z);
45 }
46 z += fractal->transformCommon.additionConstant000;
47
48 // boxoffset
49 if (fractal->transformCommon.functionEnabledxFalse
50 && aux.i >= fractal->transformCommon.startIterationsA
51 && aux.i < fractal->transformCommon.stopIterationsA) // box offset
52 {
53 CVector4 temp = z;
54 z.x = sign(z.x) * fractal->transformCommon.additionConstantA000.x + z.x;
55 z.y = sign(z.y) * fractal->transformCommon.additionConstantA000.y + z.y;
56 z.z = sign(z.z) * fractal->transformCommon.additionConstantA000.z + z.z;
57
58 if (fractal->transformCommon.functionEnabledAFalse)
59 {
60 double tempL = temp.Length();
61 // if (tempL < 1e-21) tempL = 1e-21;
62 double avgScale = z.Length() / tempL;
63 aux.DE = aux.DE * avgScale + 1.0;
64 }
65 }
66
67 if (fractal->transformCommon.functionEnabledFalse)
68 {
69 CVector4 zA = (aux.i == fractal->transformCommon.intA) ? z : CVector4();
70 CVector4 zB = (aux.i == fractal->transformCommon.intB) ? z : CVector4();
71
72 z = (z * fractal->transformCommon.scale1) + (zA * fractal->transformCommon.offset)
73 + (zB * fractal->transformCommon.offset0);
74 aux.DE *= fractal->transformCommon.scale1;
75 }
76 }
77