⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphic.part4.h

📁 C语言库函数介绍
💻 H
📖 第 1 页 / 共 2 页
字号:
       getch();
       exit(1);
    }
    maxx=getmaxx();
    x=0;
    y=getmaxy()/2;
    draw_arrow(x,y);
    size=imagesize(x,y-ARROW_SIZE,x+(4*ARROW_SIZE),y+ARROW_SIZE);
    arrow=malloc(size);
    getimage(x,y-ARROW_SIZE,x+(4*ARROW_SIZE),y+ARROW_SIZE,arrow);
    while (!kbhit())
    {
        putimage(x,y-ARROW_SIZE,arrow,XOR_PUT);
        x+=ARROW_SIZE;
        if(x>=maxx) x=0;
        putimage(x,y-ARROW_SIZE,arrow,XOR_PUT);
    }
    free(arrow);
    closegraph();
    return 0;
}


@函数名称:     line
函数原型:     void far line(int x1, int y1, int x2, int y2)
函数功能:     画直线
函数返回:
参数说明:     x1,y1,x2,y2-直线的起点和终点坐标
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    int xmax,ymax;
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode!=grOk)
    {
       printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    setcolor(getmaxcolor());
    xmax=getmaxx();
    ymax=getmaxy();
    line(0,0,xmax,ymax);
    getch();
    closegraph();
    return 0;
}


@函数名称:     lineto
函数原型:     void far lineto(int x, int y)
函数功能:     从当前位置到指定位置画直线
函数返回:
参数说明:     x,y 直线的终点坐标
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main()
{
    int gdriver=DETECT,gmode,errorcode;
    char msg[80];

    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode=graphresult();
    if (errorcode!=grOk)
    {
       printf("Graphics error: %s\n",grapherrormsg(errorcode));
       printf("Press any key to halt:");
       getch();
       exit(1);
    }
	/* move the C.P. to location (20, 30) */
    moveto(20,30);
	/* create and output a message at (20, 30) */
    sprintf(msg," (%d, %d)",getx(),gety());
    outtextxy(20,30,msg);

    lineto(100,100);
    /* create and output a message at C.P. */
    sprintf(msg,"(%d,%d)",getx(),gety());
    outtext(msg);
    /* clean up */
    getch();
    closegraph();
    return 0;
}


@函数名称:     linerel
函数原型:     void far linerel(int deltax, int deltay)
函数功能:     从当前位置开始,在x,y方向按deltax,deltay增量画直线
函数返回:
参数说明:     deltax,deltay-直线的增量
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    char msg[80];
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode!=grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    moveto(20,30);
    sprintf(msg," (%d,%d)",getx(),gety());
    outtextxy(20,30,msg);
    linerel(100,100);
    sprintf(msg," (%d,%d)",getx(),gety());
    outtext(msg);
    getch();
    closegraph();
    return 0;
}


@函数名称:     lowvideo
函数原型:     void lowvideo(void)
函数功能:     将字符屏幕显示改为低亮度
函数返回:
参数说明:
所属文件:     <graphics.h>

#include <conio.h>
int main()
{
    clrscr();
    highvideo();
    cprintf("High Intesity Text");
    lowvideo();
    gotoxy(1,2);
    cprintf("Low Intensity Text");
    return 0;
}


@函数名称:     registerbgidriver
函数原型:     int registerbgidriver(void (*driver)(void))
函数功能:     注册已连接的图形驱动器程序
函数返回:
参数说明:     driver-图形驱动器函数,该函数由系统提供,其名称和对应的用途如下:
		CGA_driver,EGAVGA_driver-对于PC机,一般使用该图形驱动器
		IBM8514_driver,Herc_driver,ATT_driver,PC3270_driver
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    errorcode=registerbgidriver(EGAVGA_driver);
    if(errorcode<0)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode!=grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    line(0,0,getmaxx(),getmaxy());
    getch();
    closegraph();
    return 0;
}


@函数名称:     restorecrtmode
函数原型:     void far restorecrtmode(void)
函数功能:     将屏幕恢复到调用initgraph以前的工作模式
函数返回:
参数说明:
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    int x,y;
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode!=grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    x=getmaxx()/2;
    y=getmaxy()/2;
    settextjustify(CENTER_TEXT,CENTER_TEXT);
    outtextxy(x,y,"Press any key to exit graphics:");
    getch();
    restorecrtmode();
    printf("We're now in text mode.");
    printf("Press any key to return to graphics mode:");
    getch();
    setgraphmode(getgraphmode());
    settextjustify(CENTER_TEXT,CENTER_TEXT);
    outtextxy(x,y,"We're back in graphics mode.");
    outtextxy(x,y+textheight("W"),"Press any key to halt:");
    getch();
    closegraph();
    return 0;
}


@函数名称:     setactivepage
函数原型:     void far setactivepage(int page)
函数功能:     设置图形函数操作的页面
函数返回:
参数说明:     该页面不等于显示的页面,EGA/VGA图形系统可有2个页面。page-页面号0或1
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=EGA,gmode=EGAHI,errorcode;
    int x,y,ht;
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode != grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    x=getmaxx()/2;
    y=getmaxy()/2;
    ht=textheight("W");
    setactivepage(1);
    line(0,0,getmaxx(),getmaxy());
    settextjustify(CENTER_TEXT,CENTER_TEXT);
    outtextxy(x,y,"This is page #1:");
    outtextxy(x,y+ht,"Press any key to halt:");
    setactivepage(0);
    outtextxy(x,y,"This is page #0.");
    outtextxy(x,y+ht,"Press any key to view page #1:");
    getch();
    setvisualpage(1);
    getch();
    closegraph();
     return 0;
}


@函数名称:     setvisualpage
函数原型:     void far setvisualpage(int page)
函数功能:     设置可显示的图形页面
函数返回:
参数说明:     page-图形操作页面,对于VGA:480X640*16色的模式,
		有2个图形页,可以设置一个为显示页面,一个为图形操作页面。
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=EGA,gmode=EGAHI,errorcode;
    int x,y,ht;
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode != grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
    exit(1);
    }
    x=getmaxx()/2;
    y=getmaxy()/2;
    ht=textheight("W");
    setactivepage(1);
    line(0,0,getmaxx(),getmaxy());
    settextjustify(CENTER_TEXT,CENTER_TEXT);
    outtextxy(x,y,"This is page #1:");
    outtextxy(x,y+ht,"Press any key to halt:");
    setactivepage(0);
    outtextxy(x,y,"This is page #0.");
    outtextxy(x,y+ht,"Press any key to view page #1:");
    getch();
    setvisualpage(1);
    getch();
    closegraph();
    return 0;
}


@函数名称:     setlinestyle
函数原型:     void far setlinestyle(int linestyle, unsigned upattern, int thickness)
函数功能:     设置画线模式
函数返回:
参数说明:     linestyle 画线风格,取值和含义如下:
                      SOLID_LINE =0  实线
                      DOTTED_LINE=1  点线
                      CENTER_LINE=2  中心线
                     DASHED_LINE =3  虚线
                     USERBIT_LINE=4  用户自定义模式
    upattern-在linestyle=USERBIT_LINE时,表示自定义的线型, thickness-线宽,有2个取值:
                     NORM_WIDTH =1   1个象素宽度
                     THICK_WIDTH=3   3个象素宽度
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
char *lname[]={"SOLID_LINE","DOTTED_LINE","CENTER_LINE","DASHED_LINE","USERBIT_LINE"};
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    int style,midx,midy,userpat;
    char stylestr[40];
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode != grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
       printf("Press any key to halt:");
        getch();
        exit(1);
    }
    midx=getmaxx()/2;
    midy=getmaxy()/2;
    userpat=1;
    for (style=SOLID_LINE; style<=USERBIT_LINE; style++)
    {
        setlinestyle(style,userpat,1);
        strcpy(stylestr,lname[style]);
        line(0,0,midx-10,midy);
        rectangle(0,0,getmaxx(),getmaxy());
        outtextxy(midx,midy,stylestr);
       getch();
        cleardevice();
    }
    closegraph();
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -