缉毒警察吴光林:C语言程序设计

来源:百度文库 编辑:神马品牌网 时间:2024/05/03 10:18:43
bar()
cirde()
ellipse()
floodficl()
line()
putpixel()
setfollstyle()
在C语言中分别代表什么意思?

这些都是c的标准库函数,下面是几个是常用的跟举的例子,更多的建议像楼上说的自己找资料学习。
1.bar
函数名: bar
功 能: 画一个二维条形图
用 法: void far bar(int left, int top, int right, int bottom);
程序例:

#include
#include
#include
#include

int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy, i;

/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");

/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}

midx = getmaxx() / 2;
midy = getmaxy() / 2;

/* loop through the fill patterns */
for (i=SOLID_FILL; i
{
/* set the fill style */
setfillstyle(i, getmaxcolor());

/* draw the bar */
bar(midx-50, midy-50, midx+50,
midy+50);

getch();
}

/* clean up */
closegraph();
return 0;
}
——————————————————
2.ellipse()
函数名: ellipse
功 能: 画一椭圆
用 法: void far ellipse(int x, int y, int stangle, int endangle,
int xradius, int yradius);
程序例:

#include
#include
#include
#include

int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
int stangle = 0, endangle = 360;
int xradius = 100, yradius = 50;

/* initialize graphics, local variables */
initgraph(&gdriver, &gmode, "");

/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)
/* an error occurred */
{
printf("Graphics error: %s\n",
grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
/* terminate with an error code */
}

midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());

/* draw ellipse */
ellipse(midx, midy, stangle, endangle,
xradius, yradius);

/* clean up */
getch();
closegraph();
return 0;
}
————————————————
3.line()
函数名: line
功 能: 在指定两点间画一直线
用 法: void far line(int x0, int y0, int x1, int y1);
程序例:

#include
#include
#include
#include

int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int xmax, ymax;

/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");

/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n",
grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}

setcolor(getmaxcolor());
xmax = getmaxx();
ymax = getmaxy();

/* draw a diagonal line */
line(0, 0, xmax, ymax);

/* clean up */
getch();
closegraph();
return 0;
}

——————————————————————
4.putpixel()
函数名: putpixel
功 能: 在指定位置画一像素
用 法: void far putpixel (int x, int y, int pixelcolor);
程序例:

#include
#include
#include
#include
#include

#define PIXEL_COUNT 1000
#define DELAY_TIME 100 /* in milliseconds */

int main(void)
{
/* request autodetection */
int gdriver = DETECT, gmode, errorcode;
int i, x, y, color, maxx, maxy, maxcolor, seed;

/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");

/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}

maxx = getmaxx() + 1;
maxy = getmaxy() + 1;
maxcolor = getmaxcolor() + 1;

while (!kbhit())
{
/* seed the random number generator */
seed = random(32767);
srand(seed);
for (i=0; i
{
x = random(maxx);
y = random(maxy);
color = random(maxcolor);
putpixel(x, y, color);
}

delay(DELAY_TIME);
srand(seed);
for (i=0; i
{
x = random(maxx);
y = random(maxy);
color = random(maxcolor);
if (color == getpixel(x, y))
putpixel(x, y, 0);
}
}

/* clean up */
getch();
closegraph();
return 0;
}
————————————————————————
5.setfollstyle()
函数名: setfillstyle
功 能: 设置填充模式和颜色
用 法: void far setfillstyle(int pattern, int color);
程序例:

#include
#include
#include
#include
#include

/* the names of the fill styles supported */
char *fname[] = { "EMPTY_FILL",
"SOLID_FILL",
"LINE_FILL",
"LTSLASH_FILL",
"SLASH_FILL",
"BKSLASH_FILL",
"LTBKSLASH_FILL",
"HATCH_FILL",
"XHATCH_FILL",
"INTERLEAVE_FILL",
"WIDE_DOT_FILL",
"CLOSE_DOT_FILL",
"USER_FILL"
};

int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int style, midx, midy;
char stylestr[40];

/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");

/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}

midx = getmaxx() / 2;
midy = getmaxy() / 2;

for (style = EMPTY_FILL; style < USER_FILL; style++)
{
/* select the fill style */
setfillstyle(style, getmaxcolor());

/* convert style into a string */
strcpy(stylestr, fname[style]);

/* fill a bar */
bar3d(0, 0, midx-10, midy, 0, 0);

/* output a message */
outtextxy(midx, midy, stylestr);

/* wait for a key */
getch();
cleardevice();
}

/* clean up */
getch();
closegraph();
return 0;
}

到图书管借一本<<C语言库函数大全>>就查得到了.
好象ellipse()是画圆
line()是画直线的