#include <QtWidgets>
class ApollonianGasketFractal : public QWidget
{
public:
ApollonianGasketFractal(QWidget *parent = 0);
protected:
void paintEvent(QPaintEvent *);
private:
void drawFractal(QPainter& painter, qreal x1, qreal y1, qreal x2, qreal y2,
qreal x3, qreal y3, int depth);
};
ApollonianGasketFractal::ApollonianGasketFractal(QWidget *parent)
: QWidget(parent)
{
setFixedSize(500, 500);
}
void ApollonianGasketFractal::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(Qt::transparent);
painter.setBrush(QBrush(Qt::black));
qreal x1 = 50.0;
qreal y1 = 250.0;
qreal x2 = 450.0;
qreal y2 = 250.0;
qreal x3 = 250.0;
qreal y3 = 26.6;
drawFractal(painter, x1, y1, x2, y2, x3, y3, 7);
}
void ApollonianGasketFractal::drawFractal(QPainter& painter, qreal x1, qreal y1, qreal x2, qreal y2,
qreal x3, qreal y3, int depth)
{
if (depth <= 0)
return;
// 计算内切圆的半径和位置
qreal r = qSqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))/2.0;
qreal x = (x1 + x2)/2.0;
qreal y = (y1 + y2)/2.0;
// 绘制内切圆
painter.drawEllipse(QPointF(x, y), r, r);
// 递归绘制内切圆和外切圆之间的三个内切圆
drawFractal(painter, x1, y1, x, y+r, x3, y3, depth-1);
drawFractal(painter, x, y+r, x2, y2, x3, y3, depth-1);
drawFractal(painter, x, y-r, x3, y3, x2, y2, depth-1);
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ApollonianGasketFractal w;
w.show();
return a.exec();
}
一个qt/c++ demo,用于显示 Apollonian Gasket(阿波罗尼恩镂垫) 分形图
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