C++ arc() Function - Draw a Curve or Circle

- July 12, 2018
Arc function cpp


The arc() function is used to draw a circular arc / curve starting from a specified angle and up to another special specified angle, along the fixed centered point (x,y) with specified radius. The general syntax of arc() function is as follows:

arc (x,y, stangle, endangle, radius);
Where:
x & y It represents the center point of the arc. These are the x-coordinate and y-coordinate of the center of the arc on the screen.
stangle It represents the starting angle of the arc in degree.
endangle It represents the ending angle of the arc in degree.
radius It represents the radius of the arc.

All the five parameters are of int type. These may be constants or variables.

Note: The arc() function can also be used to draw a circle by giving the starting angle 0 (zero) and ending angle 360 degree. Similarly, it can also be used to draw line by giving the same values for starting and ending angles.

Example of arc() Function

The following program code draws arcs with different radius, colors, starting angles & ending angles and having the same center point.

#include<graphics.h>
#include<canio.h>
using namespace std;
main()
{
      int d, m, r, co;
      d = DETECT;      //Auto-detect
      initgraph (&d, &m, " ");
      cleardevice();
      for (co = 1; co<= 15; co++)
       {
         setcolor (co);
         arc (300, 200, 45, 145, co*10);
       }
cleardevice();
}

Example 2: The following program draws circle with different radii & colors and having the same center point by using arc function.

#include<graphics>
#include<canio.h>
using namespace std;
main()
{
      int d, m, r, co;
      d = DETECT;      //Auto-detect
      initgraph (&d, &m, " ");
      cleardevice();
      for (co = 1; co<= 15; co++)
       {
         setcolor (co);
         arc (300, 200, 0, 360, co*10);
       }
getch();
closegraph();
}

Leave your reply.
EmoticonEmoticon

 

Start typing and press Enter to search