Drawing a circle

I am attempting to draw a circle using the gl_Triangle_Fan. Here is what I have thus far:

int i;
	int triangles = 20; // number of triangles
	float twoPi = 2.0f * 3.14159f;
	glVertex2f(my_x,my_y); // origin
	for(i = 0; i <= triangles; i++) { 
		glVertex2f((radius * cos(i *  twoPi / triangles)), 
				   (radius * sin(i * twoPi / triangles)));

my_x and my_y are the positions of the mouse.

When the program begins, there is a semicircle in the bottom left-hand corner of the screen, but when I click a new location, the circle becomes a massive line that enfulges the screen. Any help would be greatly appreciated

The whys and wherefores of what happens when you click your mouse can’t really be determined from the code you’ve posted. I suspect it’s something to do with the GLUT screen refresh as it sounds like that kind of problem.

Try this web page for what you want :

you move the center but you are not moving the other points.