Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QCoreApplication>
- #include <iostream>
- #include <complex>
- #include <math.h>
- #include <QColor>
- #include <QImage>
- //zakres układu współrzędnych
- const float MinX = -2.5;
- const float MaxX = 1.5;
- const float MaxY = 1.25;
- const float MinY = -1.25;
- const int Iterations = 50;
- //kolory
- const int w1 = 50;
- const int w2 = 50;
- const int w3 = 50;
- const int p1 = 2.2;
- const int p2 = 2.2;
- const int p3 = 2.2;
- const int c1 = 1/4;
- const int c2 = 1/2;
- const int c3 = 3/4;
- float isSequenceConvergent(std::complex<float> z_0, std::complex<float> constant,int UsedIt)
- {
- int i=0;
- for(; i< UsedIt; ++i)
- {
- std::complex<float> z_1 = pow(z_0,2) + constant;
- if(abs(z_1) >= 2) break;
- z_0 = z_1;
- }
- return i;
- }
- QColor computeColor(int x)
- {
- int red = exp(-w1 * pow(abs(x-c1),p1));
- int green = exp(-w2 * pow(abs(x-c2),p2));
- int blue = exp(-w3 * pow(abs(x-c3),p3));
- return QColor(red,green,blue);
- }
- int main(int argc, char *argv[])
- {
- QCoreApplication a(argc, argv);
- std::cout << "Generator zbiorow Mandelbrota \n Podaj szerokosc obrazu: \n";
- int width =0;
- std::cin >> width;
- int height = (int) (width * (MaxY - MinY)/(MaxX -MinX));
- float unit = (MaxX - MinX)/width;
- QImage image(width,height,QImage::Format_RGB888);
- std::complex<float> C_0(MinX,MaxY);
- std::complex<float> C = C_0;
- for(int i =0; i<width;++i)
- {
- C = C - C.real() + C_0.real();
- for(int j = 0; j <height; ++j)
- {
- float color = isSequenceConvergent(0,C, Iterations) /Iterations;
- image.setPixel(i,j,computeColor(color).Rgb);
- C = C+std::complex<float>(unit,0);
- }
- C = C - std::complex<float>(0,unit);
- }
- image.save("Wygenerowane Zdjęie.png",0,100);
- std::cout << "Zrobione!";
- return a.exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment