How to draw a rectangle in c graphics? And simple math behind the rectangle function in c graphics

To draw a rectangle in c graphics we will use rectangle( ), graphics.h header file, and some graphic driver codes to initialize graphic mode.
Here in this code, you can see there are four arguments are present within rectangle( ).
rectangle(150,150,350,250).So here you have to pass four arguments within rectangle( ).

rectangle(150,150,350,250);

To understand the rectangle( ), and arguments of rectangle( ), let us consider the rectangle function like this.

void rectangle(int left,int top,int right,int bottom); or rectangle( left,top,right,bottom);


 To draw a rectangle in c graphics we need two coordinates, so the left top of the rectangle will be the first coordinate and the right bottom of the rectangle will be the second coordinate of the rectangle.

rectangle(left,top,right,bottom); or rectangle(150,150,350,250);

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void main( )
{
clrscr( );
int gd=DETECT,gm;
initgraph(&gd,&gm,"c\\tc\\bgi");
rectangle(150,150,350,250);
getch( );
closegraph( );
}






Comments

Popular posts from this blog

Graphics with c/c++