Guest User

Untitled

a guest
May 15th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <QCoreApplication>
  2. #include <iostream>
  3. #include <complex>
  4. #include <math.h>
  5. #include <QColor>
  6. #include <QImage>
  7.  
  8. //zakres układu współrzędnych
  9. const float MinX = -2.5;
  10. const float MaxX = 1.5;
  11. const float MaxY = 1.25;
  12. const float MinY = -1.25;
  13.  
  14. const int Iterations = 50;
  15.  
  16. //kolory
  17. const int w1 = 50;
  18. const int w2 = 50;
  19. const int w3 = 50;
  20.  
  21. const int p1 = 2.2;
  22. const int p2 = 2.2;
  23. const int p3 = 2.2;
  24.  
  25. const int c1 = 1/4;
  26. const int c2 = 1/2;
  27. const int c3 = 3/4;
  28.  
  29. float isSequenceConvergent(std::complex<float> z_0, std::complex<float> constant,int UsedIt)
  30. {
  31.     int i=0;
  32.     for(; i< UsedIt; ++i)
  33.     {
  34.        std::complex<float> z_1 = pow(z_0,2) + constant;
  35.        if(abs(z_1) >= 2) break;
  36.        z_0 = z_1;
  37.     }
  38.     return i;
  39. }
  40.  
  41. QColor computeColor(int x)
  42. {
  43.  
  44.     int red = exp(-w1 * pow(abs(x-c1),p1));
  45.     int green = exp(-w2 * pow(abs(x-c2),p2));
  46.     int blue = exp(-w3 * pow(abs(x-c3),p3));
  47.  
  48.     return QColor(red,green,blue);
  49. }
  50.  
  51. int main(int argc, char *argv[])
  52. {
  53.     QCoreApplication a(argc, argv);
  54.  
  55.     std::cout << "Generator zbiorow Mandelbrota \n Podaj szerokosc obrazu: \n";
  56.     int width =0;
  57.     std::cin >> width;
  58.  
  59.     int height = (int) (width * (MaxY - MinY)/(MaxX -MinX));
  60.     float unit = (MaxX - MinX)/width;
  61.     QImage image(width,height,QImage::Format_RGB888);
  62.  
  63.  
  64.     std::complex<float> C_0(MinX,MaxY);
  65.     std::complex<float> C = C_0;
  66.  
  67.     for(int i =0; i<width;++i)
  68.     {
  69.         C = C - C.real() + C_0.real();
  70.         for(int j = 0; j <height; ++j)
  71.         {
  72.             float color = isSequenceConvergent(0,C, Iterations) /Iterations;
  73.             image.setPixel(i,j,computeColor(color).Rgb);
  74.             C = C+std::complex<float>(unit,0);
  75.         }
  76.         C = C - std::complex<float>(0,unit);
  77.     }
  78.  
  79.     image.save("Wygenerowane Zdjęie.png",0,100);
  80.  
  81.     std::cout << "Zrobione!";
  82.  
  83.     return a.exec();
  84. }
Advertisement
Add Comment
Please, Sign In to add comment