#include <QtWidgets>
#include <QPainter>
class HexagonalGosperCurve : public QWidget {
public:
HexagonalGosperCurve(QWidget *parent = nullptr) : QWidget(parent) {
QPixmap pixmap("https://upload.wikimedia.org/wikipedia/commons/thumb/9/9c/Heighway_Hexagonal_Gosper_curve.gif/220px-Heighway_Hexagonal_Gosper_curve.gif");
setFixedSize(600, 600);
setWindowTitle("Hexagonal Gosper Curve(六角高斯波曲线)");
image = QImage(size(), QImage::Format_RGB32);
image.fill(Qt::white);
drawHexagonalGosperCurve();
label = new QLabel(this);
label->setPixmap(pixmap.scaledToWidth(400));
label->move(100, 450);
}
private:
QImage image;
QLabel* label;
void drawHexagonalGosperCurve(int n = 4, double size = 200.0, double x = 300.0, double y = 300.0, double angle = 0.0) {
if (n == 0) {
return;
}
double cos60 = cos(M_PI / 3);
double sin60 = sin(M_PI / 3);
double x1 = x + size * cos(angle);
double y1 = y + size * sin(angle);
double x2 = x1 + size * cos(angle + M_PI / 3);
double y2 = y1 + size * sin(angle + M_PI / 3);
double x3 = x2 + size * cos(angle - M_PI / 3);
double y3 = y2 + size * sin(angle - M_PI / 3);
double x4 = x3 + size * cos(angle - M_PI);
double y4 = y3 + size * sin(angle - M_PI);
double x5 = x4 + size * cos(angle - M_PI - M_PI / 3);
double y5 = y4 + size * sin(angle - M_PI - M_PI / 3);
double x6 = x5 + size * cos(angle - M_PI + M_PI / 3);
double y6 = y5 + size * sin(angle - M_PI + M_PI / 3);
drawHexagonalGosperCurve(n - 1, size / sqrt(7.0), x, y, angle);
drawHexagonalGosperCurve(n - 1, size / sqrt(7.0), x1, y1, angle + M_PI / 3);
drawHexagonalGosperCurve(n - 1, size / sqrt(7.0), x2, y2, angle + M_PI / 3);
drawHexagonalGosperCurve(n - 1, size / sqrt(7.0), x3, y3, angle - M_PI / 3);
drawHexagonalGosperCurve(n - 1, size / sqrt(7.0), x4, y4, angle - M_PI);
drawHexagonalGosperCurve(n - 1, size / sqrt(7.0), x5, y5, angle - M_PI - M_PI / 3);
drawHexagonalGosperCurve(n - 1, size / sqrt(7.0), x6, y6, angle - M_PI + M_PI / 3);
QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(Qt::black);
painter.drawLine(x, y, x1, y1);
painter.drawLine(x1, y1, x2, y2);
painter.drawLine(x2, y2, x3, y3);
painter.drawLine(x3, y3, x4, y4);
painter.drawLine(x4, y4, x5, y5);
painter.drawLine(x5, y5, x6, y6);
}
void paintEvent(QPaintEvent* /* event */) {
QPainter painter(this);
painter.drawImage(0, 0, image);
painter.end();
}
};
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
HexagonalGosperCurve window;
window.show();
return app.exec();
}
一个qt/c++ demo,用于显示 Hexagonal Gosper Curve(六角高斯波曲线) 分形图
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