Paul Heidmann Fractal Example  1.0
fractalOne.cpp
Go to the documentation of this file.
1 // Copyright (C) 2014 Paul S. Heidmann
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // For a copy of the GNU General Public License see
14 // <http://www.gnu.org/licenses/>.
15 //
16 // Author contact info:
17 // Paul Heidmann
18 // paul@heidmann.com
19 
20 #include <fractalOne.hpp>
21 
22 #include <stdexcept>
23 
24 namespace FO=fractalOne;
25 
26 namespace
27 {
29  const std::uint32_t maxIters,
30  const FO::cmplxType& z,
31  const std::uint32_t numIters )
32 {
33  const FO::fltType scaleFactor{
34  static_cast<FO::fltType>(numIters) / static_cast<FO::fltType>(maxIters) };
35  const FO::fltType colorMagnitude{
36  static_cast<FO::fltType>(0xff) * scaleFactor };
37  const std::uint32_t color{ static_cast<std::uint32_t>(colorMagnitude) };
38 
39  if( std::abs( z + 6.0 ) < 0.1 )
40  return( std::move( std::make_tuple(
41  color, 0x00, color ) ) );
42  if( std::abs( z + 4.0 ) < 0.1 )
43  return( std::move( std::make_tuple(
44  color, color, 0x00 ) ) );
45  if( std::abs( z - 3.0 ) < 0.1 )
46  return( std::move( std::make_tuple(
47  color, 0x00, 0x00 ) ) );
48  if( std::abs( z - 5.0 ) < 0.1 )
49  return( std::move( std::make_tuple(
50  0x00, color, 0x00 ) ) );
51  if( std::abs( z - 7.0 ) < 0.1 )
52  return( std::move( std::make_tuple(
53  0x00, 0x00, color ) ) );
54  throw( std::runtime_error( "Unknown zero..." ) );
55 }
56 
57 FO::cmplxType f( const FO::cmplxType& z )
58 {
59  // zeros are -6, -4, 3, 5, 7
60  const FO::cmplxType z_2{ z * z };
61  const FO::cmplxType z_3{ z_2 * z };
62  const FO::cmplxType z_4{ z_3 * z };
63  const FO::cmplxType z_5{ z_4 * z };
64  return( z_5 - (5.0 * z_4) - (55.0 * z_3) + (245.0 * z_2) + (654.0 * z) - 2520.0 );
65 }
66 
67 FO::cmplxType f_prime( const FO::cmplxType& z )
68 {
69  const FO::cmplxType z_2{ z * z };
70  const FO::cmplxType z_3{ z_2 * z };
71  const FO::cmplxType z_4{ z_3 * z };
72  return( (5.0 * z_4) - (20.0 * z_3) - (165.0 * z_2) + (490.0 * z) + 654.0 );
73 }
74 
75 }
76 
77 std::shared_ptr<FO::fractalParamsType>
79 {
80 #if 0
81  const FO::cmplxType lowerLeft{ 4.5, 7.9 };
82  const FO::cmplxType upperRight{ 5.7, 9.1 };
83  const FO::cmplxType delta{ 0.0005, 0.0005 };
84 #else
85  const FO::cmplxType lowerLeft{ 4.9, 8.4 };
86  const FO::cmplxType upperRight{ 5.1, 8.6 };
87  const FO::cmplxType delta{ 0.00005, 0.00005 };
88 #endif
89  const FO::fltType zEpsilon{ 0.05 };
90  const std::vector<FO::cmplxType> zeros{
91  FO::cmplxType{ -6.0, 0.0 },
92  FO::cmplxType{ -4.0, 0.0 },
93  FO::cmplxType{ 3.0, 0.0 },
94  FO::cmplxType{ 5.0, 0.0 },
95  FO::cmplxType{ 7.0, 0.0 } };
96  const std::uint32_t maxIters{ 50 };
97 
98  const std::shared_ptr<FO::fractalParamsType> fParams{
99  std::make_shared<FO::fractalParamsType>(
100  lowerLeft,
101  upperRight,
102  delta,
103  zEpsilon,
104  f,
105  f_prime,
106  zeros,
107  maxIters,
108  colorForZero ) };
109  return( fParams );
110 }
std::tuple< std::uint8_t, std::uint8_t, std::uint8_t > colorType
This type is used to declare variables that hold the color of a given pixel in the fractal...
double fltType
Definition: fractalOne.hpp:39
std::complex< fltType > cmplxType
Definition: fractalOne.hpp:41
std::shared_ptr< fractalParamsType > getFractalParams(void)
Definition: fractalOne.cpp:78