博客专栏

EEPW首页 > 博客 > C语言绘图教程例子5-1

C语言绘图教程例子5-1

发布人:chen3bing 时间:2024-05-15 来源:工程师 发布文章

代码

#include <graphics.h>
#include <math.h>

void polygon(x0,y0,a,n,af)
int x0,y0,a,n;
	float af;
{
	
	
		int x,y,i;
		float dtheta,theta;
		if(n<3) return;
		dtheta=6.28318/n;
		theta=af*0.0174533;
		moveto(x0,y0);
		x=x0;
		y=y0;
		for(i=1;i<n;i++)
		{
			x=x+a*cos(theta);
			y=y+a*sin(theta);
			lineto(x,y);
			theta=theta+dtheta;
		}
		lineto(x0,y0);
	}

 int main()
 {

	

	
	int i,a=80,x=200,y=100;
	int gdriver=DETECT,gmode;
	initgraph(&gdriver,&gmode,"c\\tc");
	cleardevice();
	setbkcolor(9);
	setcolor(4);
	for(i=3;i<=10;i++)
	polygon(x,y,a,i,0); 

		
		
 getch();
 
return 0;
 }

运行

1710053115378.jpg

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。



关键词: C语言绘图

技术专区

关闭