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

📄 graphic.part2.h

📁 C语言库函数介绍
💻 H
📖 第 1 页 / 共 2 页
字号:
函数功能:     设置图形模式下图形函数操作的窗口大小
函数返回:
参数说明:     left,top,right,bottom-窗口大小坐标,clip-是否剪切超出的内容
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define CLIP_ON 1
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    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());
    outtextxy(0,0,"* <-- (0,0) in default viewport");
    setviewport(50,50,getmaxx()-50,getmaxy()-50,CLIP_ON);
    outtextxy(0,0,"* <-- (0,0) in smaller viewport");
    getch();
    closegraph();
    return 0;
}


@函数名称:     cleardevice
函数原型:     void far cleardevice(void)
函数功能:     清除屏幕显示,仅用于图形工作方式
函数返回:
参数说明:
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    int midx,midy;
    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;
    setcolor(getmaxcolor());
    settextjustify(CENTER_TEXT,CENTER_TEXT);
    outtextxy(midx,midy,"press any key to clear the screen:");
    getch();
    cleardevice();
    outtextxy(midx,midy,"press any key to quit:");
    getch();
    closegraph();
    return 0;
}


@函数名称:     getmaxx,getmaxy
函数原型:     int far getmaxx(void)
              int far getmaxy(void)
函数功能:     得到当前图形模式下最大有效X,Y坐标数值
函数返回:
参数说明:
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    int midx,midy;
    char xrange[80],yrange[80];
    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;
    sprintf(xrange,"X values range from 0..%d",getmaxx());
    sprintf(yrange,"Y values range from 0..%d",getmaxy());
    settextjustify(CENTER_TEXT,CENTER_TEXT);
    outtextxy(midx,midy,xrange);
    outtextxy(midx,midy+textheight("W"),yrange);
    getch();
    closegraph();
    return 0;
}


@函数名称:     moveto
函数原型:     void far moveto(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,);
    errorcode=graphresult();
    if (errorcode!=grOk)
    {
        printf("Graphics error: %s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    moveto(20,30);
    putpixel(getx(),gety(),getmaxcolor());
    sprintf(msg," (%d,%d)",getx(),gety());
    outtextxy(20,30,msg);
    moveto(100,100);
    putpixel(getx(),gety(),getmaxcolor());
    sprintf(msg," (%d,%d)",getx(),gety());
    outtext(msg);
    getch();
    closegraph();
    return 0;
}


@函数名称:     moverel
函数原型:     void far moverel(int dx, int dy)
函数功能:     移动图形模式下的光标位置
函数返回:
参数说明:     dx,dy-光标从当前位置移动的相对位置
所属文件:     <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);
    putpixel(getx(),gety(),getmaxcolor());
    sprintf(msg," (%d,%d)",getx(),gety());
    outtextxy(20,30,msg);
    moverel(100,100);
    putpixel(getx(),gety(),getmaxcolor());
    sprintf(msg," (%d,%d)",getx(),gety());
    outtext(msg); getch();
    closegraph();
    return 0;
}


@函数名称:     bar
函数原型:     void bar(int left, int top, int right, int bottom)
函数功能:     画矩形,并填充矩形内部区域
函数返回:
参数说明:     left,top-屏幕左上角坐标,right,bottom-屏幕右下角坐标
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    int midx,midy,i;
    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;
    for (i=SOLID_FILL;i<USER_FILL;i++)
    {
       setfillstyle(i,getmaxcolor());
        bar(midx-50,midy-50,midx+50,midy+50);
        getch();
    }
    closegraph();
    return 0;
}


@函数名称:     bar3d
函数原型:     void bar3d(int left,int top,int right,int bottom,int depth, int topflag)
函数功能:     画2维矩形,并填充矩形内部区域
函数返回:
参数说明:     left,top-屏幕左上角坐标,right,bottom-屏幕左上角坐标
              depth-三维深度,topflag-0:不画顶盖,非0:画顶盖
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    int midx,midy,i;
    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;
    for (i=EMPTY_FILL; i<USER_FILL; i++)
    {
        setfillstyle(i,getmaxcolor());
        bar3d(midx-50,midy-50,midx+50,midy+50,10,1);
        getch();
    }
    closegraph();
    return 0;
}


@函数名称:     rectangle
函数原型:     void far rectangle(int left, int top, int right, int bottom)
函数功能:     图形方式下,在屏幕上画一个矩形
函数返回:
参数说明:     left, top, right,bottom-矩形的左上角和右下角坐标
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    int left,top,right,bottom;
    initgraph(&gdriver,&gmode,);
    errorcode=graphresult();
    if (errorcode!=grOk)
    {
        printf("Graphics error:%s",grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);
    }
    left=getmaxx()/2-50;
    top=getmaxy()/2-50;
    right=getmaxx()/2+50;
    bottom=getmaxy()/2+50;
    rectangle(left,top,right,bottom);
    getch();
    closegraph();
    return 0;
}


@函数名称:     setcolor
函数原型:     void far setcolor(int color)
函数功能:     设置前景颜色
函数返回:
参数说明:     颜色值含义如下:
		0-BLACK         黑     深色0-7 
		1-BLUE          兰     2-GREEN      绿
		3-CYAN          青     4-RED        红
		5-MAGENTA       洋红   6-BROWN      棕
		7-LIGHTGRAY     淡灰   8-DARKGRAY   深灰    淡色8-15
		9-LIGHTBLUE     淡兰   10-LIGHTGREEN 淡绿
		11-LIGHTCYAN    淡青   12-LIGHTRED  淡红
		13-LIGHTMAGENTA 淡洋红 4-YELLOW     黄
		15-WHITE        白
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=EGA,gmode=EGAHI,errorcode;
    int color,maxcolor,x,y;
    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);
    }
    maxcolor=getmaxcolor();
     settextjustify(CENTER_TEXT,CENTER_TEXT);
    x=getmaxx()/2;
    y=getmaxy()/2;
    for (color=1;color<=maxcolor;color++)
    {
        cleardevice();
        setcolor(color);
        sprintf(msg,"Color: %d",color);
        outtextxy(x,y,msg);
        getch();
    }
    closegraph();
    return 0;
}


@函数名称:     getcolor
函数原型:     int getcolor(void)
函数功能:     得到当前画线颜色
函数返回:     颜色值
参数说明:
所属文件:     <graphics.h>

#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
int main()
{
    int gdriver=DETECT,gmode,errorcode;
    int color,midx,midy;
    char colname[35];
    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;
    setcolor(getmaxcolor());
    settextjustify(CENTER_TEXT,CENTER_TEXT);
    color=getcolor();
    itoa(color,colname,10);
    strcat(colname,"is the current drawing color.");
    outtextxy(midx,midy,colname);
    getch();
    closegraph();
    return 0;
}

⌨️ 快捷键说明

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