#include <QtWidgets>
#include <QPainter>
class Dendrite : public QWidget {
public:
Dendrite(QWidget *parent = nullptr) : QWidget(parent) {
QPixmap pixmap("https://upload.wikimedia.org/wikipedia/commons/thumb/f/fe/Dendrit-1.png/220px-Dendrit-1.png");
setFixedSize(600, 600);
setWindowTitle("Dendrite 分形图案");
image = QImage(size(), QImage::Format_RGB32);
image.fill(Qt::white);
drawDendrite();
label = new QLabel(this);
label->setPixmap(pixmap.scaledToWidth(400));
label->move(100, 450);
}
private:
QImage image;
QLabel* label;
void drawLine(QPainter& painter, double x1, double y1, double x2, double y2) {
painter.drawLine(QPointF(x1, y1), QPointF(x2, y2));
}
void drawDendrite(QPainter& painter, double x1, double y1, double x2, double y2, int level) {
if (level <= 0) {
drawLine(painter, x1, y1, x2, y2);
return;
}
double x3 = (2 * x1 + x2) / 3;
double y3 = (2 * y1 + y2) / 3;
double x4 = (x1 + 2 * x2) / 3;
double y4 = (y1 + 2 * y2) / 3;
double x5 = (x3 + x4) / 2 - (y4 - y3) * sqrt(3) / 2;
double y5 = (y3 + y4) / 2 - (x3 - x4) * sqrt(3) / 2;
drawDendrite(painter, x1, y1, x3, y3, level - 1);
drawDendrite(painter, x3, y3, x5, y5, level - 1);
drawDendrite(painter, x5, y5, x4, y4, level - 1);
drawDendrite(painter, x4, y4, x2, y2, level - 1);
}
void drawDendrite() {
QPainter painter(&image);
painter.setPen(QPen(Qt::black, 2));
drawDendrite(painter, 50, 300, 550, 300, 8);
painter.end();
}
void paintEvent(QPaintEvent* /* event */) {
QPainter painter(this);
painter.drawImage(0, 0, image);
painter.end();
}
};
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
Dendrite window;
window.show();
return app.exec();
}
一个qt/c++ demo,用于显示 Dendrite(树枝形图案) 分形图
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