Mid point circle


/*
* main.c
*
* Created on: Apr 29, 2014
* Author: akshaythakare
*/

#include <stdio.h>
#include <stdlib.h>
#include <openGL/gl.h>
#include <openGL/glu.h>
#include <GLUT/glut.h>

float xc,yc,r;

void plotx(float xk,float yk)
{
glBegin(GL_POINTS);
glVertex2f(xc+xk,yc+yk);
glVertex2f(xc+xk,yc-yk);
glVertex2f(xc-xk,yc+yk);
glVertex2f(xc-xk,yc-yk);
glVertex2f(xc+yk,yc+xk);
glVertex2f(xc+yk,yc-xk);
glVertex2f(xc-yk,yc+xk);
glVertex2f(xc-yk,yc-xk);
glEnd();
}
void circle()
{
float xk,yk,d;
xk=0;
yk=r;
d=5/4.0 -r;
while(xk<yk)
{
if(d<0)
{
xk=xk+1;
d = d + 2*xk+1;
}
else
{
xk=xk+1;
yk=yk-1;
d = d + 2*(xk-yk)+1;
}
plotx(xk,yk);
}
}

void disp()
{
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,1,1);
circle();
glFlush();
}

int main(int argv, char ** argc)
{
printf("Enter the co-ord of the center of the circle and radius = ");
scanf("%f%f%f",&xc,&yc,&r);
glutInit(&argv,argc);
glutInitWindowSize(300,300);
glutCreateWindow("Circle");
gluOrtho2D(0,300,0,300);
glutDisplayFunc(disp);
glutMainLoop();
return 0;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s