插入一段漂亮的代码片
代码片
#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;
}