在C图形中绘制矩形

矩形() 用于绘制矩形。绘制矩形需要左上角和右下角的坐标。left指定左上角的X坐标,top指定左上角的Y坐标,right指定右下角的X坐标,bottom指定右下角的Y坐标。 语法:

null
rectangle(int left, int top, int right, int bottom);

例如:

Input : left = 150, top = 250, right = 450, bottom = 350;
Output : 
图片[1]-在C图形中绘制矩形-yiteyi-C++库

Input : left = 150, top = 150, right = 450, bottom = 450;
Output : 
图片[2]-在C图形中绘制矩形-yiteyi-C++库

下面是矩形函数的实现:

// C program to draw a rectangle
#include <graphics.h>
// Driver code
int main()
{
// gm is Graphics mode which is a computer display
// mode that generates image using pixels.
// DETECT is a macro defined in "graphics.h" header file
int gd = DETECT, gm;
// location of left, top, right, bottom
int left = 150, top = 150;
int right = 450, bottom = 450;
// initgraph initializes the graphics system
// by loading a graphics driver from disk
initgraph(&gd, &gm, "" );
// rectangle function
rectangle(left, top, right, bottom);
getch();
// closegraph function closes the graphics
// mode and deallocates all memory allocated
// by graphics system .
closegraph();
return 0;
}


输出:

图片[2]-在C图形中绘制矩形-yiteyi-C++库
© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享