Draw a line in C++

Graphics is one of the main feature of c++. By using Graphics we can draw any shape.#include<graphics.h> header files defines a number of graphics function like

Point…….simply a pair(x,y)representing a coordinate in the window

Circle…….defines by a point and a radius

Line………Two points one is starting point and other is the end point

Message…..Used to display in the graphics window.

 

/* ============== Program Description ============= */

/*   draw a picture using graphics line()         */

/* ================================================== */

#include <graphics.h> //header file is used for graphics

#include <math.h>   //for math calculation like cos, sin

#include <conio.h>

void main(void)

{

   int   driver = DETECT,mode;

   int   x[10],y[10];

   int   x_center = 360, y_center = 180, rad = 100;

   int   i,j;

   initgraph(&driver,&mode,"c:\\tc\\bgi");

   for ( i = 0; i < 10; i++ )

   {

       x[i] = x_center + rad * cos(36*i*3.14159/180);

       y[i] = y_center + rad * sin(36*i*3.14159/180);

   }

   for ( i = 0; i < 10; i++ )

       for ( j = 0; j < 10; j++ )

                line(x[i],y[i],x[j],y[j]);

   getch();          

   closegraph();

}

Output...

graphics in C++

Explaination..

The cos function computes the cosine of x (measured in radians). It returns a value in the range of -1 to 1.

The sin functions compute the sine of x (measured in radians).

About Us

Rekha SetiaRekha Setia is a passionate blogger of Extra Computer Notes. if you have any ideas or any request me @