In C++, the rectangle() function is used to draw a Rectangle between two given points on the screen. The general syntax of this function are looks like this:
rectangle(x1, y1, x2, y2);
Where:
x1 & y1 | represent the x and y co-ordinates of the first point. |
x2 & y2 | represent the x and y co-ordinates of the second point. |
All the above parameters are of "int" data type. These may be integer type values or variables.
For example, to draw a rectangle between Upper Left Corner and bottom right corner of the screen, the statement will be as follows:
rectangle(0, 0, 639, 479);
rectangle(639, 479, 0, 0);
In the above statement, point (0, 0) represents the upper left corner of the screen and point (639, 479) represents the bottom right corner of the VGA screen.
Example of rectangle() Function
The following C++ program draws a rectangle between two points (150, 300) & (500, 250).
#include
#include
#include
using namespace std;
main()
{
int driver, mode;
driver = DETECT;
initgraph (&driver, &m, " ");
cleardevice();
rectangle(150, 300, 500, 250);
getch();
closegraph();
}