#include <QtWidgets>
class CantorDustFractal : public QWidget
{
public:
CantorDustFractal(QWidget *parent = 0);
protected:
void paintEvent(QPaintEvent *);
private:
void drawFractal(QPainter& painter, int xPos, int yPos, int sideLength);
};
CantorDustFractal::CantorDustFractal(QWidget *parent)
: QWidget(parent)
{
setFixedSize(350, 200);
}
void CantorDustFractal::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(Qt::black);
painter.setBrush(QBrush(Qt::white));
int xPos = 30;
int yPos = 100;
int sideLength = 250;
drawFractal(painter, xPos, yPos, sideLength);
}
void CantorDustFractal::drawFractal(QPainter& painter, int xPos, int yPos, int sideLength)
{
if (sideLength < 2)
{
painter.drawRect(xPos, yPos, sideLength, sideLength);
return;
}
// 计算子正方形的边长和位置
int subLength = sideLength / 3;
int subXPos = xPos + subLength;
// 绘制 7 个子图形,除去中心的那个子正方形
drawFractal(painter, xPos, yPos, subLength, subLength);
drawFractal(painter, xPos + subLength * 2, yPos, subLength, subLength);
drawFractal(painter, xPos, yPos + subLength * 2, subLength, subLength);
drawFractal(painter, xPos + subLength * 2, yPos + subLength * 2, subLength, subLength);
drawFractal(painter, subXPos, yPos, subLength, subLength);
drawFractal(painter, subXPos, yPos + subLength * 2, subLength, subLength);
drawFractal(painter, xPos + subLength, yPos + subLength, subLength, subLength);
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
CantorDustFractal w;
w.show();
return a.exec();
}
一个qt/c++ demo,用于显示 Cantor Dust(康托尔尘埃) 分形图
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