Slavik9510

Untitled

Oct 16th, 2023
1,059
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <QApplication>
  2. #include <QImage>
  3. #include <QLabel>
  4. #include <complex>
  5. #include <cmath>
  6.  
  7. // Функція для обчислення Множини Жюльї з використанням tg(z)
  8. void computeJuliaSet(QImage &image) {
  9.     int width = image.width();
  10.     int height = image.height();
  11.     double maxIter = 256;
  12.  
  13.     for (int x = 0; x < width; x++) {
  14.         for (int y = 0; y < height; y++) {
  15.             std::complex<double> z(0, 0);
  16.             std::complex<double> c(
  17.                 2.0 * (x - width / 2) / (width - 1),
  18.                 2.0 * (y - height / 2) / (height - 1)
  19.             );
  20.  
  21.             int iter = 0;
  22.             while (iter < maxIter && std::abs(z) < 2.0) {
  23.                 z = std::tan(z) + c;
  24.                 iter++;
  25.             }
  26.  
  27.             if (iter < maxIter) {
  28.                 // Колір для точки, яка не підлягає обмеженню
  29.                 image.setPixel(x, y, qRgb(iter * 8, iter * 4, iter * 16));
  30.             } else {
  31.                 // Колір для точки, яка підлягає обмеженню
  32.                 image.setPixel(x, y, qRgb(0, 0, 0));
  33.             }
  34.         }
  35.     }
  36. }
  37.  
  38. int main(int argc, char *argv[]) {
  39.     QApplication app(argc, argv);
  40.  
  41.     int width = 800;
  42.     int height = 800;
  43.     QImage image(width, height, QImage::Format_RGB32);
  44.  
  45.     computeJuliaSet(image);
  46.  
  47.     QLabel label;
  48.     label.setPixmap(QPixmap::fromImage(image));
  49.     label.show();
  50.  
  51.     return app.exec();
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment