#include <QtWidgets>
#include <QPainter>
class BurningShip : public QWidget {
public:
BurningShip(QWidget *parent = nullptr) : QWidget(parent) {
QPixmap pixmap("https://upload.wikimedia.org/wikipedia/commons/thumb/7/72/Burning_ship_fractal_zoom_e-126.png/220px-Burning_ship_fractal_zoom_e-126.png");
setFixedSize(600, 600);
setWindowTitle("Burning Ship Fractal(沉船分形)");
image = QImage(size(), QImage::Format_RGB32);
image.fill(Qt::white);
drawBurningShip();
label = new QLabel(this);
label->setPixmap(pixmap.scaledToWidth(400));
label->move(100, 450);
}
private:
QImage image;
QLabel* label;
void drawBurningShip() {
double min_x = -1.8;
double max_x = -1.5;
double min_y = -0.1;
double max_y = 0.2;
int width = image.width();
int height = image.height();
double x_step = (max_x - min_x) / width;
double y_step = (max_y - min_y) / height;
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
double c_real = min_x + x * x_step;
double c_imag = min_y + y * y_step;
double z_real = c_real;
double z_imag = c_imag;
int iterations = 0;
while (z_real * z_real + z_imag * z_imag <= 4 && iterations < 255) {
double z_real_new = z_real * z_real - z_imag * z_imag + c_real;
double z_imag_new = 2 * fabs(z_real * z_imag) + c_imag;
z_real = z_real_new;
z_imag = z_imag_new;
iterations++;
}
image.setPixel(x, y, qRgb(iterations, iterations, iterations));
}
}
}
void paintEvent(QPaintEvent* /* event */) {
QPainter painter(this);
painter.drawImage(0, 0, image);
painter.end();
}
};
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
BurningShip window;
window.show();
return app.exec();
}
一个qt/c++ demo,用于显示 Burning Ship Fractal(沉船分形) 分形图
2023-04-24 浏览:
标签ad报错:该广告ID(7)不存在。
- 热门标签
-
- 最新发布
-
- Qt 信号槽与原编译系统(2024-06-04)
- Qt信号槽关联中使用普通变量关联(包含不修改和修改槽内数据两种)、使用引用变量关联对(2023-05-05)
- 一个qt/c++ demo,用于显示 Koch Snowflake (科赫雪花) 分(2023-04-24)
- 一个qt/c++ demo,用于显示 Peano Curve(皮亚诺曲线) 分形图(2023-04-24)
- 一个qt/c++ demo,用于显示 Apollonian Gasket(阿波罗尼恩(2023-04-24)
- 一个qt/c++ demo,用于显示 Terdragon Curve(三头龙曲线)(2023-04-24)
- 一个qt/c++ demo,用于显示 Spiral Fractal(螺旋分形) 分形(2023-04-24)
- 一个qt/c++ demo,用于显示 Sierpinski Tetrahedron((2023-04-24)
- 一个qt/c++ demo,用于显示 Gasket Fractal(镂垫分形) 分(2023-04-24)
- 一个qt/c++ demo,用于显示 Hexagonal Gosper Curve(2023-04-24)
- 半年热点
-
-
一个Qt/C++ Demo,用于实现一个用于显示3D瀑布图的控件效果
浏览: 1097
-
一个qt/c++ demo,用于显示分星图
浏览: 1015