Advertisement
Guest User

Untitled

a guest
May 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.65 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "Fractal.h"
  4.  
  5.  
  6.  
  7.  
  8. class BarnsleyFern : public Fractal{
  9. public:
  10.     BarnsleyFern(const float XWINDOW, const float YWINDOW);
  11.  
  12.     void CalculatePoints() ;
  13.     void CalcProbability() ;
  14.  
  15.     float Map_pointX(float x)override;
  16.     float Map_pointY(float y)override;
  17.    
  18.  
  19.     void Func_1(int iteration);
  20.     void Func_2(int iteration);
  21.     void Func_3(int iteration);
  22.     void Func_4(int iteration);
  23. };
  24.  
  25.  
  26.  
  27. BarnsleyFern::BarnsleyFern(const float XWINDOW, const float YWINDOW)
  28. :Fractal(XWINDOW, YWINDOW)
  29. {
  30.     CalculatePoints();
  31.     MapAllPoints();
  32. }
  33.  
  34.  
  35.  
  36.  
  37. void BarnsleyFern::CalcProbability(){
  38.     m_probability = rand()%100+1;
  39.     //std::cout << "probability -> " <<  m_probability << std::endl;
  40. }
  41.  
  42.  
  43.  
  44. void BarnsleyFern::Func_1(int iteration){
  45.  
  46.  
  47.     //std::cout << " FUNC 1 " << std::endl;
  48.     m_xy[iteration].first  =  0 * m_xy[iteration-1].first + 0    * m_xy[iteration-1].second;
  49.     m_xy[iteration].second =  0 * m_xy[iteration-1].first + 0.16 * m_xy[iteration-1].second;
  50.    
  51.    
  52. }
  53.  
  54. void BarnsleyFern::Func_2(int iteration){
  55.     //std::cout << " FUNC 2 " << std::endl;
  56.     m_xy[iteration].first  =   0.85 * m_xy[iteration-1].first + 0.04 * m_xy[iteration-1].second;
  57.     m_xy[iteration].second =  -0.04 * m_xy[iteration-1].first + 0.85 * m_xy[iteration-1].second + 1.2f;
  58. }
  59.  
  60. void BarnsleyFern::Func_3(int iteration){
  61.     //std::cout << " FUNC 3 " << std::endl;
  62.     m_xy[iteration].first  =  0.20 * m_xy[iteration-1].first + -0.26  * m_xy[iteration-1].second;
  63.     m_xy[iteration].second =  0.23 * m_xy[iteration-1].first +  0.22  * m_xy[iteration-1].second + 1.6f;
  64. }
  65.  
  66. void BarnsleyFern::Func_4(int iteration){
  67.     //std::cout << " FUNC 4 " << std::endl;
  68.     m_xy[iteration].first  =  -0.15 * m_xy[iteration-1].first + 0.28   * m_xy[iteration-1].second;
  69.     m_xy[iteration].second =   0.26 * m_xy[iteration-1].first + 0.24 * m_xy[iteration-1].second + 0.44f;
  70. }
  71.  
  72. void BarnsleyFern::CalculatePoints(){
  73.     srand(time(NULL));
  74.  
  75.     for(int i = 1; i < ITERATION_MAX; ++i){
  76.         CalcProbability();
  77.  
  78.         if(0 < m_probability && m_probability <= 1){
  79.             Func_1(i);
  80.         }
  81.         else if(1 < m_probability && m_probability <= 86){
  82.             Func_2(i);
  83.         }
  84.         else if(86 < m_probability && m_probability <= 93){
  85.             Func_3(i);
  86.         }
  87.         else if(93 < m_probability && m_probability <= 100){
  88.             Func_4(i);
  89.         }
  90.  
  91.     }
  92. }
  93.  
  94.  
  95. float BarnsleyFern::Map_pointX(float x){
  96.     return  static_cast<float>(0.14 * m_xwindow * x + m_xwindow / 2.0 -30);
  97. }
  98.  
  99. float BarnsleyFern::Map_pointY(float y){
  100.     return  static_cast<float>(0.135 * m_ywindow * y -20);
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement