谢宾斯基三角形

插入一段漂亮的代码片

代码片

#include <graphics.h>
#include <conio.h>
#include <stdlib.h>

void sanjiaoxing(int x, int y, int color)
{
	// 设置画线颜色
	setlinecolor(color);

	// 画三角形的三条边
	line(x, y, x + 10, y);
	line(x, y, x, y + 10);
	line(x + 10, y, x, y + 10);
}

typedef struct point
{
	double x;
	double y;
}point;

int main()
{
	int n, i;
	initgraph(640, 480);	// 初始化图形窗口
	point P[3]= { {320, 50}, {120, 400}, {520, 400} }; // 设定三角形的三个顶点
	point p;
	p.x = rand() % 640;
	p.y = rand() % 480;
	// 绘制十万个点
	for (i = 0; i <= 100000; i++)
	{
		n = rand()%3;
		p.x = (p.x + P[n].x) / 2;
		p.y = (p.y + P[n].y) / 2;
		if (i > 100) // 前100个点先不绘画,先等迭代稳定下来
		{
			putpixel((int)p.x, (int)p.y, GREEN);
		}
	}
	
	_getch();				// 按任意键继续
	closegraph();			// 关闭图形窗口
	return 0;
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值