为什么出现这句话 BGI Error: Graphics not initialized (use 'initgraph')
用TC运行时出现 BGI Error: Graphics not initialized (use 'initgraph')源码是
程序代码:
#include <stdio.h> #include <graphics.h>/*加入c图形库*/ #include <math.h> #include <conio.h> yidong(int dx,int dy)/*实现移动函数*/ { moveto(320+dx,240-dy); lineto(420+dx,120-dy); lineto(450+dx,140-dy); lineto(320+dx,240-dy);/*变换三角形三个点的坐标实现移动变换*/ } bilie(float Sx,float Sy) /*实现比例函数*/ { moveto(320*Sx,240*Sy); lineto(420*Sx,120*Sy); lineto(450*Sx,140*Sy); lineto(320*Sx,240*Sy); /*变换三角形三个点的坐标实现比列变换*/ } xuanzhuan(float a) /*实现旋转函数*/ { float p; moveto(320,240); lineto(320+(420-320)*cos(a)-(240-120)*sin(a),240-(420-320)*sin(a)-(240-120)*cos(a)); lineto(320+(450-320)*cos(a)-(240-140)*sin(a),240-(450-320)*sin(a)-(240-140)*cos(a)); lineto(320,240); /*变换三角形三个点的坐标实现旋转变换*/ } main() { int i,j; float X,Y,bx,by,a; int gdriver=DETECT,gmode; /*初始化显示模式参数*/ initgraph(&gdriver,&gmode,""); /*初始化显示为默认的640*480、16色模式 */ i=20; j=240; moveto(i,j); for(i=20;i<=620;i+=20) /*使用双循环画点函数画出表格中的纵坐标*/ lineto(i,240); i=320; j=20; moveto(i,j); for(j=20;j<=460;j+=20) /*使用双循环画点函数画出表格中的横坐标*/ lineto(320,j); moveto(320,240); lineto(420,120); lineto(450,140); lineto(320,240);/*画出需变换的三角形,其三个顶点分别为(320,240); (420,120) ;(450,140)*/ printf("please input X,Y to move:"); scanf("%f%f",&X,&Y); /*输入移动量 */ yidong(X,Y); printf("please input bx,by to scale:"); scanf("%f%f",&bx,&by); /*输入x方向,y方向缩放大小 */ bilie(bx,by); printf("please input a to circumgyrate:"); scanf("%f",&a); /*输入旋转角度,a为正,则逆时针旋转*/ xuanzhuan(a); }