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:
Where:
arc (x,y, stangle, endangle, radius);
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
#include
using namespace std;
main()
{
int d, m, r, co;
d = DETECT; //Auto-detect
initgraph (&d, &m, " ");
cleardevice();
for (co = 1; co {
setcolor (co);
arc (300, 200, 45, 145, co*10);
}
cleardevice();
}
Example 2:
#include
#include
using namespace std;
main()
{
int d, m, r, co;
d = DETECT; //Auto-detect
initgraph (&d, &m, " ");
cleardevice();
for (co = 1; co {
setcolor (co);
arc (300, 200, 0, 360, co*10);
}
getch();
closegraph();
}