C语言中的作图问题

作者&投稿:银奚 (若有异议请与网页底部的电邮联系)
C语言作图问题~

先进入图形显示模式才能作图!~

Turbo C提供了非常丰富的图形函数, 所有图形函数的原型均在graphics. h中, 本节主要介绍图形模式的初始化、独立图形程序的建立、基本图形功能、图形窗口以及图形模式下的文本输出等函数。另外, 使用图形函数时要确保有显示器图形驱动程序*BGI, 同时将集成开发环境Options/Linker中的Graphics lib选为on, 只有这样才能保证正确使用图形函数。由于种类比较多,所以下面仅列举2个例子,抛砖引玉→
1.点
void far putpixel(int x, int y, int color);
2.线
void far line(int x0, int y0, int x1, int y1); 画一条从点(x0, y0)到(x1, y1)的直线。

void far lineto(int x, int y); 画一作从现行游标到点(x, y)的直线。

void far linerel(int dx, int dy); 画一条从现行游标(x, y)到按相对增量确定的点(x+dx, y+dy)的直线。

void far circle(int x, int y, int radius); 以(x, y)为圆心, radius为半径, 画一个圆。

c语言的图形部分是很有意思的!也是c中最精彩的内容之一,希望你能很快享受它的乐趣!

你没有把graphics.h放在头文件夹下吧,还是没有这个头文件?
这是 graphics.h的代码,自己再TC或VC安装目录下的include文件夹下建个graphics.h文件(用记事本就行)

/* graphics.h

Definitions for Graphics Package.

Copyright (c) Borland International 1987,1988
All Rights Reserved.
*/

#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif

#if !defined(__GRAPHX_DEF_)
#define __GRAPHX_DEF_

enum graphics_errors { /* graphresult error return codes */
grOk = 0,
grNoInitGraph = -1,
grNotDetected = -2,
grFileNotFound = -3,
grInvalidDriver = -4,
grNoLoadMem = -5,
grNoScanMem = -6,
grNoFloodMem = -7,
grFontNotFound = -8,
grNoFontMem = -9,
grInvalidMode = -10,
grError = -11, /* generic error */
grIOerror = -12,
grInvalidFont = -13,
grInvalidFontNum = -14,
grInvalidVersion = -18
};

enum graphics_drivers { /* define graphics drivers */
DETECT, /* requests autodetection */
CGA, MCGA, EGA, EGA64, EGAMONO, IBM8514, /* 1 - 6 */
HERCMONO, ATT400, VGA, PC3270, /* 7 - 10 */
CURRENT_DRIVER = -1
};

enum graphics_modes { /* graphics modes for each driver */
CGAC0 = 0, /* 320x200 palette 0; 1 page */
CGAC1 = 1, /* 320x200 palette 1; 1 page */
CGAC2 = 2, /* 320x200 palette 2: 1 page */
CGAC3 = 3, /* 320x200 palette 3; 1 page */
CGAHI = 4, /* 640x200 1 page */
MCGAC0 = 0, /* 320x200 palette 0; 1 page */
MCGAC1 = 1, /* 320x200 palette 1; 1 page */
MCGAC2 = 2, /* 320x200 palette 2; 1 page */
MCGAC3 = 3, /* 320x200 palette 3; 1 page */
MCGAMED = 4, /* 640x200 1 page */
MCGAHI = 5, /* 640x480 1 page */
EGALO = 0, /* 640x200 16 color 4 pages */
EGAHI = 1, /* 640x350 16 color 2 pages */
EGA64LO = 0, /* 640x200 16 color 1 page */
EGA64HI = 1, /* 640x350 4 color 1 page */
EGAMONOHI = 0, /* 640x350 64K on card, 1 page - 256K on card, 4 pages */
HERCMONOHI = 0, /* 720x348 2 pages */
ATT400C0 = 0, /* 320x200 palette 0; 1 page */
ATT400C1 = 1, /* 320x200 palette 1; 1 page */
ATT400C2 = 2, /* 320x200 palette 2; 1 page */
ATT400C3 = 3, /* 320x200 palette 3; 1 page */
ATT400MED = 4, /* 640x200 1 page */
ATT400HI = 5, /* 640x400 1 page */
VGALO = 0, /* 640x200 16 color 4 pages */
VGAMED = 1, /* 640x350 16 color 2 pages */
VGAHI = 2, /* 640x480 16 color 1 page */
PC3270HI = 0, /* 720x350 1 page */
IBM8514LO = 0, /* 640x480 256 colors */
IBM8514HI = 1 /*1024x768 256 colors */
};

/* Colors for setpalette and setallpalette */

#if !defined(__COLORS)
#define __COLORS

enum COLORS {
BLACK, /* dark colors */
BLUE,
GREEN,
CYAN,
RED,
MAGENTA,
BROWN,
LIGHTGRAY,
DARKGRAY, /* light colors */
LIGHTBLUE,
LIGHTGREEN,
LIGHTCYAN,
LIGHTRED,
LIGHTMAGENTA,
YELLOW,
WHITE
};
#endif

enum CGA_COLORS {
CGA_LIGHTGREEN = 1, /* Palette C0 Color Names */
CGA_LIGHTRED = 2,
CGA_YELLOW = 3,

CGA_LIGHTCYAN = 1, /* Palette C1 Color Names */
CGA_LIGHTMAGENTA = 2,
CGA_WHITE = 3,

CGA_GREEN = 1, /* Palette C2 Color Names */
CGA_RED = 2,
CGA_BROWN = 3,

CGA_CYAN = 1, /* Palette C3 Color Names */
CGA_MAGENTA = 2,
CGA_LIGHTGRAY = 3
};

enum EGA_COLORS {
EGA_BLACK = 0, /* dark colors */
EGA_BLUE = 1,
EGA_GREEN = 2,
EGA_CYAN = 3,
EGA_RED = 4,
EGA_MAGENTA = 5,
EGA_BROWN = 20,
EGA_LIGHTGRAY = 7,
EGA_DARKGRAY = 56, /* light colors */
EGA_LIGHTBLUE = 57,
EGA_LIGHTGREEN = 58,
EGA_LIGHTCYAN = 59,
EGA_LIGHTRED = 60,
EGA_LIGHTMAGENTA = 61,
EGA_YELLOW = 62,
EGA_WHITE = 63
};

enum line_styles { /* Line styles for get/setlinestyle */
SOLID_LINE = 0,
DOTTED_LINE = 1,
CENTER_LINE = 2,
DASHED_LINE = 3,
USERBIT_LINE = 4, /* User defined line style */
};

enum line_widths { /* Line widths for get/setlinestyle */
NORM_WIDTH = 1,
THICK_WIDTH = 3,
};

enum font_names {
DEFAULT_FONT = 0, /* 8x8 bit mapped font */
TRIPLEX_FONT = 1, /* "Stroked" fonts */
SMALL_FONT = 2,
SANS_SERIF_FONT = 3,
GOTHIC_FONT = 4
};

#define HORIZ_DIR 0 /* left to right */
#define VERT_DIR 1 /* bottom to top */

#define USER_CHAR_SIZE 0 /* user-defined char size */

enum fill_patterns { /* Fill patterns for get/setfillstyle */
EMPTY_FILL, /* fills area in background color */
SOLID_FILL, /* fills area in solid fill color */
LINE_FILL, /* --- fill */
LTSLASH_FILL, /* /// fill */
SLASH_FILL, /* /// fill with thick lines */
BKSLASH_FILL, /* \\\ fill with thick lines */
LTBKSLASH_FILL, /* \\\ fill */
HATCH_FILL, /* light hatch fill */
XHATCH_FILL, /* heavy cross hatch fill */
INTERLEAVE_FILL, /* interleaving line fill */
WIDE_DOT_FILL, /* Widely spaced dot fill */
CLOSE_DOT_FILL, /* Closely spaced dot fill */
USER_FILL /* user defined fill */
};

enum putimage_ops { /* BitBlt operators for putimage */
COPY_PUT, /* MOV */
XOR_PUT, /* XOR */
OR_PUT, /* OR */
AND_PUT, /* AND */
NOT_PUT /* NOT */
};

enum text_just { /* Horizontal and vertical justification
for settextjustify */
LEFT_TEXT = 0,
CENTER_TEXT = 1,
RIGHT_TEXT = 2,

BOTTOM_TEXT = 0,
/* CENTER_TEXT = 1, already defined above */
TOP_TEXT = 2
};

#define MAXCOLORS 15

struct palettetype {
unsigned char size;
signed char colors[MAXCOLORS+1];
};

struct linesettingstype {
int linestyle;
unsigned upattern;
int thickness;
};

struct textsettingstype {
int font;
int direction;
int charsize;
int horiz;
int vert;
};

struct fillsettingstype {
int pattern;
int color;
};

struct pointtype {
int x, y;
};

struct viewporttype {
int left, top, right, bottom;
int clip;
};

struct arccoordstype {
int x, y;
int xstart, ystart, xend, yend;
};

void far _Cdecl arc(int x, int y, int stangle, int endangle,
int radius);
void far _Cdecl bar(int left, int top, int right, int bottom);
void far _Cdecl bar3d(int left, int top, int right, int bottom,
int depth, int topflag);
void far _Cdecl circle(int x, int y, int radius);
void far _Cdecl cleardevice(void);
void far _Cdecl clearviewport(void);
void far _Cdecl closegraph(void);
void far _Cdecl detectgraph(int far *graphdriver,int far *graphmode);
void far _Cdecl drawpoly(int numpoints, int far *polypoints);
void far _Cdecl ellipse(int x, int y, int stangle, int endangle,
int xradius, int yradius);
void far _Cdecl fillellipse( int x, int y, int xradius, int yradius );
void far _Cdecl fillpoly(int numpoints, int far *polypoints);
void far _Cdecl floodfill(int x, int y, int border);
void far _Cdecl getarccoords(struct arccoordstype far *arccoords);
void far _Cdecl getaspectratio(int far *xasp, int far *yasp);
int far _Cdecl getbkcolor(void);
int far _Cdecl getcolor(void);
struct palettetype * far _Cdecl getdefaultpalette( void );
char * far _Cdecl getdrivername( void );
void far _Cdecl getfillpattern(char far *pattern);
void far _Cdecl getfillsettings(struct fillsettingstype far *fillinfo);
int far _Cdecl getgraphmode(void);
void far _Cdecl getimage(int left, int top, int right, int bottom,
void far *bitmap);
void far _Cdecl getlinesettings(struct linesettingstype far *lineinfo);
int far _Cdecl getmaxcolor(void);
int far _Cdecl getmaxmode(void);
int far _Cdecl getmaxx(void);
int far _Cdecl getmaxy(void);
char * far _Cdecl getmodename( int mode_number );
void far _Cdecl getmoderange(int graphdriver, int far *lomode,
int far *himode);
unsigned far _Cdecl getpixel(int x, int y);
void far _Cdecl getpalette(struct palettetype far *palette);
int far _Cdecl getpalettesize( void );
void far _Cdecl gettextsettings(struct textsettingstype far *texttypeinfo);
void far _Cdecl getviewsettings(struct viewporttype far *viewport);
int far _Cdecl getx(void);
int far _Cdecl gety(void);
void far _Cdecl graphdefaults(void);
char * far _Cdecl grapherrormsg(int errorcode);
void far _Cdecl _graphfreemem(void far *ptr, unsigned size);
void far * far _Cdecl _graphgetmem(unsigned size);
int far _Cdecl graphresult(void);
unsigned far _Cdecl imagesize(int left, int top, int right, int bottom);
void far _Cdecl initgraph(int far *graphdriver,
int far *graphmode,
char far *pathtodriver);
int far _Cdecl installuserdriver( char far *name, int huge (*detect)(void) );
int far _Cdecl installuserfont( char far *name );
void far _Cdecl line(int x1, int y1, int x2, int y2);
void far _Cdecl linerel(int dx, int dy);
void far _Cdecl lineto(int x, int y);
void far _Cdecl moverel(int dx, int dy);
void far _Cdecl moveto(int x, int y);
void far _Cdecl outtext(char far *textstring);
void far _Cdecl outtextxy(int x, int y, char far *textstring);
void far _Cdecl pieslice(int x, int y, int stangle, int endangle,
int radius);
void far _Cdecl putimage(int left, int top, void far *bitmap, int op);
void far _Cdecl putpixel(int x, int y, int color);
void far _Cdecl rectangle(int left, int top, int right, int bottom);
void far _Cdecl restorecrtmode(void);
void far _Cdecl sector( int X, int Y, int StAngle, int EndAngle,
int XRadius, int YRadius );
void far _Cdecl setactivepage(int page);
void far _Cdecl setallpalette(struct palettetype far *palette);
void far _Cdecl setaspectratio( int xasp, int yasp );
void far _Cdecl setbkcolor(int color);
void far _Cdecl setcolor(int color);
void far _Cdecl setfillpattern(char far *upattern, int color);
void far _Cdecl setfillstyle(int pattern, int color);
unsigned far _Cdecl setgraphbufsize(unsigned bufsize);
void far _Cdecl setgraphmode(int mode);
void far _Cdecl setlinestyle(int linestyle, unsigned upattern,
int thickness);
void far _Cdecl setpalette(int colornum, int color);
void far _Cdecl setrgbpalette(int colornum,
int red, int green, int blue);
void far _Cdecl settextjustify(int horiz, int vert);
void far _Cdecl settextstyle(int font, int direction, int charsize);
void far _Cdecl setusercharsize(int multx, int divx,
int multy, int divy);
void far _Cdecl setviewport(int left, int top, int right, int bottom,
int clip);
void far _Cdecl setvisualpage(int page);
void far _Cdecl setwritemode( int mode );
int far _Cdecl textheight(char far *textstring);
int far _Cdecl textwidth(char far *textstring);

/***** graphics drivers *****/

int _Cdecl registerbgidriver(void (*driver)(void));
int far _Cdecl registerfarbgidriver(void far *driver);

/* !! These "functions" are NOT user-callable !! */
/* !! They are there just so you can link in graphics drivers !! */

void _Cdecl CGA_driver(void);
void _Cdecl EGAVGA_driver(void);
void _Cdecl IBM8514_driver(void);
void _Cdecl Herc_driver(void);
void _Cdecl ATT_driver(void);
void _Cdecl PC3270_driver(void);

extern int far _Cdecl CGA_driver_far[];
extern int far _Cdecl EGAVGA_driver_far[];
extern int far _Cdecl IBM8514_driver_far[];
extern int far _Cdecl Herc_driver_far[];
extern int far _Cdecl ATT_driver_far[];
extern int far _Cdecl PC3270_driver_far[];

/***** graphics fonts *****/

int _Cdecl registerbgifont(void (*font)(void));
int far _Cdecl registerfarbgifont(void far *font);

/* !! These "functions" are NOT user-callable, !! */
/* !! they are there just so you can link in fonts !! */

void _Cdecl triplex_font(void);
void _Cdecl small_font(void);
void _Cdecl sansserif_font(void);
void _Cdecl gothic_font(void);

extern int far _Cdecl triplex_font_far[];
extern int far _Cdecl small_font_far[];
extern int far _Cdecl sansserif_font_far[];
extern int far _Cdecl gothic_font_far[];

#endif

首先,你的CGA和CGAC0请换成VGA和VGAHI。

tc下的错误,估计是因为你的路径设置错误导致,请检查一下你的tc设置。
vc下的错误,是因为vc不带有graphics.h,如果需要,可以安装第三方绘图库,你可以下载这个:http://code.google.com/p/vcgraphics/downloads/detail?name=EasyX_V20091123.zip

<graphics.h>是TC里面的图形库,如果要用的话应该用TC来编译,VC++有他自己的另外图形库!


R语言自定义坐标轴排序
        R语言作图时,默认情况下软件会按照自己的方式对坐标轴的项目进行排序,然而这种排序往往不是我们所希望的,因此需要想办法让坐标轴的项目按照我们希望的顺序输出。        如下所示,我有两列数据,要绘制箱线图,以第一列为Y轴,第二...

R语言作图plot函数以及参数设置解析
ann  使用T\/F对plot中的标题,x轴标签,y轴标签是否显示进行定义。axes  使用T\/F对坐标轴是否显示进行定义。frame.plot  使用T\/F对画图外框是否显示进行定义。panel.first  参数还没弄懂,panel.first="grid(8,8)"对背景线进行定义。asp  表示y\/x的纵横比...

R语言可视化及作图6--ggplot2之点图、条形图、盒形图、直方图、线图_百 ...
R语言绘图系列:标度控制着数据到图形属性的映射,标度将我们的数据转化为视觉上可以感知的东西,比如大小、位置、颜色、形状等。标度也为我们提供了读图时所使用的工具,比如说坐标轴和图例。总的来说,可以称为引导元素。标度函数控制元素的属性,可以理解为图形的遥控器,可以用它来调整画布大小、颜色...

作图语言规范是什么(包括尺规)?
1.用直尺作图时的语言规范 a.过点*作直线**;作线段**,以点*为端点作射线 b.连接点*,*以点*,为端点作线段 c.延长线段**到点*,延长线段**到点*使**= 2.用圆规作图时的语言规范 a.以点*为圆心**为半径作圆 b.以点*为圆心**为半径作弧交**于点 尺规作图应注意的问题 1.明确...

r语言导入csv作图不能显示中文
r语言导入csv作图不能显示中文是对中文不支持。R的语法是来自Scheme,R的使用与S-PLUS有很多类似之处,这两种语言有一定的兼容性。

C语言编程 文本作图 急急急!!!〒▽〒
int main() { int i, j, k, f = 0;for (i = 1; i <= 6; i++) { k = i;for (f = 1; f < i * 3 - 2; f++) { printf(" ");} for (j = 1; j <= 6; j++) { printf("%d ", k);if (k == 6) { k = 0;} if (j == 6) { printf("\\n");...

《R语言实战》自学笔记16-图形图例
参考资料: 《R语言实战》(中文版),人民邮电出版社,2013. R语言绘制图例(legend)的各种问题_详细综合解析, https:\/\/blog.csdn.net\/xiangyong58\/article\/details\/54579293 投必得R语言教程,第二讲 R作图-基础-图形参数设置:标题、图例、文字, https:\/\/mp.weixin.qq.com\/s?__biz=Mz...

Mathematica的函数作图问题
用下面的表达式就可以实现:有附图 Manipulate[Plot[a*x^2+b*x,{x,-10,10},PlotRange->All],{{a,1},-10,10,1},{{b,1},-10,10,1}]简单说一下:{x,-10,10}就是做图显示的横轴的范围,如果你愿意可以更改它的范围;{{a,1},-10,10,1},{{b,1},-10,10,1}这段就是你想要...

如何用图像识别识别出r语言作图的方法
数据收集,特征提取。1、数据收集:需要收集大量的R语言生成的图形数据,这些图形数据应当涵盖不同的图形类型,比如散点图、折线图、柱状图等,为了训练图像识别模型,还需要对应的标签,说明每个图形是由R语言生成的。2、特征提取:需要从这些图形中提取特征。的特征包括图形的布局、颜色使用、线条样式、标记...

C语言中的作图问题
C语言中的作图问题  我来答 首页 在问 全部问题 娱乐休闲 游戏 旅游 教育培训 金融财经 医疗健康 科技 家电数码 政策法规 文化历史 时尚美容 情感心理 汽车 生活 职业 母婴 三农 互联网 生产制造 其他 日报 日报精选 日报广场 用户 认证用户 视频作者 日报作者 ...

安源区13435221425: C语言画图问题! -
郟油小儿: 我都很久没用C语言的画图函数了,像画圆,画正方形,画直线,都有函数的,只不过那时候我用的编译器是win-tc,严格来讲画图这一部分不属于C语言,只是相对于编译器来说,比如想画直线就用line函数,比如我要画一个直线就是如下语句...

安源区13435221425: C语言绘制图形问题 -
郟油小儿: 修改如下://---------------------------------------------------------------------------#include void main() { int a; int i; int j; int lenth; int width; printf("1.绘制矩形:\n"); printf("2.绘制正方形:\n"); printf("3.推出、\n"); scanf("%d",&a); switch(a) { case 1:printf...

安源区13435221425: c语言画图是出现这样的错误是怎么回事? -
郟油小儿: Options->Linker->Graphics library设为On即可.

安源区13435221425: 关于用C语言画图的问题 -
郟油小儿: bar ( 左边坐标,上边坐标,右边坐标,下边坐标);宽度=右边坐标-左边坐标;高度=下边坐标-上边坐标;因为绘图长度单位是像素 (pixel) ,与屏幕大小和分辨率有关.例如分辨率 1920,屏幕宽度 30cm, 边长 15 时,方块宽度 = 30cm/1920*15 = 0.23cm.当尺寸太小时,就没法显示了.

安源区13435221425: C语言如何画图 -
郟油小儿: c语言是函数语言,所以画图也离不开各种图形函数:下面举几个简单的例子: ======================================= 1./*学用circle画圆形*/ #include "graphics.h" main() {int driver,mode,i; float j=1,k=1; driver=VGA;mode=VGAHI; ...

安源区13435221425: c语言怎么画图? -
郟油小儿: C语言本身没有提供与绘图相关的函数调用,但是调用其他图形库,就可以很轻松实现绘图功能. 比如,SDL,http://www.lazyfoo.net/SDL_tutorials/.

安源区13435221425: 分析一下C语言的一个作图题(关于函数嵌套和调用的),要详细步骤 -
郟油小儿: 你也可以看一下如下这几个简单的递归:/**2015年2月24日20:42:32 by: 我爱编程**//**功能:简单递归讲解**/#include void p(int w) { if(w>0) { p(w-1); printf("%d\n",w); } } void main() { p(3); }/**2015年2月24日20:42:32 by: 我爱编程**//**功能:求3的阶乘**/#include int p(int w) { if (w == 0) return 1; else return p(w-1) * w; } void main() { printf("%d\n",p(3)); }

安源区13435221425: c语言画图怎么画直方图? -
郟油小儿: 因为平时我们用的c语言是在文本方式下运行的,所以不能够直接用c语言画图,在用c 语言惊醒画图之前,首先应该把c语言从文本模式转换为图形模式,初始化函数是 intgraph(图形驱动器名,图形驱动器模式,图形驱动器路径);一般图形驱动器名定为DETECT,模式为gmode,路径在你安装c语言文件夹里,BGI子目录,画线的函数是line(x1,y1,x2,y2);分别是线的起始坐标.其库函数包含在<graphics.h>里

安源区13435221425: c语言 画图 问题 怎么用更好的办法打印字母三角形呢 -
郟油小儿: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17#include<stdio.h> voidmain() {inti,j=1,count=1;for(i=1;i<=26;i++){printf("%c",'A'+i-1);if(count%j==0){printf("\n");j++;count=0;}count++;}}

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网