Paul Heidmann Fractal Example  1.0
fractalTwo.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 <fractalTwo.hpp>
21 
22 #include <stdexcept>
23 
24 namespace FT=fractalTwo;
25 
26 namespace
27 {
28  constexpr FT::fltType pi{ 3.1415926535 };
29  constexpr FT::fltType twoPi{ 2.0 * pi };
30  constexpr FT::fltType threePi{ 3.0 * pi };
31  constexpr FT::fltType fourPi{ 4.0 * pi };
32  constexpr FT::fltType piOverTwo{ pi / 2.0 };
33 
35  const std::uint32_t maxIters,
36  const FT::cmplxType& z,
37  const std::uint32_t numIters )
38  {
39  const FT::fltType scaleFactor{
40  0.75 * (static_cast<FT::fltType>(numIters) / static_cast<FT::fltType>(maxIters)) + 0.25 };
41  const FT::fltType colorMagnitude{
42  static_cast<FT::fltType>(0xff) * scaleFactor };
43  const std::uint32_t color{ static_cast<std::uint32_t>(colorMagnitude) };
44 
45  if( std::abs( z + pi ) < 0.1 )
46  return( std::move( std::make_tuple(
47  color, 0x00, color ) ) );
48  if( std::abs( z ) < 0.1 )
49  return( std::move( std::make_tuple(
50  color, color, 0x00 ) ) );
51  if( std::abs( z - twoPi ) < 0.1 )
52  return( std::move( std::make_tuple(
53  color, 0x00, 0x00 ) ) );
54  if( std::abs( z - threePi ) < 0.1 )
55  return( std::move( std::make_tuple(
56  0x00, color, 0x00 ) ) );
57  if( std::abs( z - fourPi ) < 0.1 )
58  return( std::move( std::make_tuple(
59  0x00, 0x00, color ) ) );
60  throw( std::runtime_error( "Unknown zero..." ) );
61  }
62 
63  FT::cmplxType f( const FT::cmplxType& z )
64  {
65  // Use zeros at -pi, 0, pi, 2*pi, 3*pi, 4*pi
66  return( std::sin<FT::fltType>( z ) );
67  }
68 
69  FT::cmplxType f_prime( const FT::cmplxType& z )
70  {
71  return( std::cos<FT::fltType>( z ) );
72  }
73 }
74 
75 std::shared_ptr<FT::fractalParamsType> FT::getFractalParams( void )
76 {
77 #if 0
78  const FT::cmplxType lowerLeft{ (piOverTwo - 0.3), (piOverTwo - 0.65) };
79  const FT::cmplxType upperRight{ (piOverTwo + 0.3), (piOverTwo - 0.05) };
80  const FT::cmplxType delta{ 0.0001, 0.0001 };
81 #else
82  const FT::cmplxType lowerLeft{ (piOverTwo - 0.06), (piOverTwo - 0.47) };
83  const FT::cmplxType upperRight{ (piOverTwo + 0.06), (piOverTwo - 0.23) };
84  const FT::cmplxType delta{ 0.00003, 0.00003 };
85 #endif
86 
87  const FT::fltType zEpsilon{ 0.05 };
88  const std::vector<FT::cmplxType> zeros{
89  FT::cmplxType{ -pi, 0.0 },
90  FT::cmplxType{ 0.0, 0.0 },
91  FT::cmplxType{ twoPi, 0.0 },
92  FT::cmplxType{ threePi, 0.0 },
93  FT::cmplxType{ fourPi, 0.0 } };
94  const std::uint32_t maxIters{ 50 };
95 
96  const std::shared_ptr<FT::fractalParamsType> fParams{
97  std::make_shared<FT::fractalParamsType>(
98  lowerLeft,
99  upperRight,
100  delta,
101  zEpsilon,
102  f,
103  f_prime,
104  zeros,
105  maxIters,
106  colorForZero ) };
107  return( fParams );
108 }
double fltType
Definition: fractalTwo.hpp:37
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...
std::complex< fltType > cmplxType
Definition: fractalTwo.hpp:39
std::shared_ptr< fractalParamsType > getFractalParams(void)
Definition: fractalOne.cpp:78