Computer Graphics – Lab 18 Circle Using Polygon

[wpdm_package id=’1254′]
Sample Input –Write a program to draw circle approximating it with polygons of increase sides. ‘+’ and ‘-‘ should be used to increase and decrease the number of sides. ‘1’ to ‘9’ keyboard keys are used to specify the radius of circle.
Sample Output –Circle_Using_Polygon

[sourcecode lang=”cpp”]
void Circle_Using_Polygon(int a, int b, int r){
double pi=3.1415926535;
double angle=0.0;
glColor3d(0.9,0.9,0.5);
glBegin(GL_LINE_LOOP);
for(int i=0;i<polygon_side;i++){
angle=i*(2*pi)/polygon_side;
glVertex2f(a+r*cos(angle),screen_height-(b+r*sin(angle)));
}
glEnd();
glFlush();
}
[/sourcecode]

To compile the above program in ubuntu terminal –
# g++ -lGL -lGLU -lglut Circle_Using_Polygon.cpp
# ./a.out

Leave a Reply

Your email address will not be published. Required fields are marked *