Sierpinski三角形

时间:2023-03-08 16:58:30
Sierpinski三角形

转载请标明地址:http://www.cnblogs.com/wangmengmeng/

效果图:

Sierpinski三角形

通项公式:An=3的N-1次方

源代码:

 #include <graphics.h>
#include <conio.h>
#include <time.h> void main()
{
srand((unsigned)time(NULL)); // 设置随机种子
POINT P[] = {{, }, {, }, {, }}; // 设定三角形的三个顶点
POINT p = {rand() % , rand() % }; // 随机产生当前点 // 初始化图形模式
initgraph(, ); setbkcolor(WHITE);
cleardevice(); // 绘制三万个点
int n;
for(int i = ; i <= ; i++)
{
n = rand() % ;
p.x = (p.x + P[n].x) / ;
p.y = (p.y + P[n].y) / ;
putpixel(p.x, p.y, GREEN);
} // 按任意键退出
getch();
closegraph();
}