Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

#include <windows.h> //COSC420 #include <GL/glut.

h>

int x1=0, y1=0, d=0,ct=0; constintscreenWidth = 640; constintscreenHeight = 480; constintbotm = 50; constint left = 50; constint top = 480-50; constint right = 640-50;

voidinit ( void ){ glClearColor(1.0,1.0,1.0,0.0); glColor3f(0.0f, 0.0f, 0.0f); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, (GLdouble)screenWidth, 0.0, (GLdouble)screenHeight); }

void cir1(intx,inty,int r){ glBegin(GL_POINTS); x1=0;y1=r;d=1-r;

glVertex2i(x1+x, y1+y); glVertex2i(y1+x,x1+y); glVertex2i(y1+x,-x1+y); glVertex2i(x1+x,-y1+y); glVertex2i(-x1+x,-y1+y); glVertex2i(-y1+x,-x1+y); glVertex2i(-y1+x,x1+y); glVertex2i(-x1+x,y1+y); while(y1>x1) { if(d<0) d=d+(2*x1)+3; else { d=d+((2*x1)-(2*y1))+5; y1--; } x1++; glVertex2i(x1+x, y1+y); glVertex2i(y1+x,x1+y); glVertex2i(y1+x,-x1+y); glVertex2i(x1+x,-y1+y); glVertex2i(-x1+x,-y1+y); glVertex2i(-y1+x,-x1+y); glVertex2i(-y1+x,x1+y);

glVertex2i(-x1+x,y1+y); } glEnd(); }

voiddoMouse(int button, int state, int x, int y){

if (x >= 590) x = 590 - 1; if (y <= 50) y = 50 + 1; if (x <= 50) x = 50 + 1; if (y >= 430) y = 430 + 1;

if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN &&ct==0){ glBegin(GL_POINTS); glVertex2i(x, (screenHeight-y) ); x1=x; y1=y; glEnd(); ct++; }

else if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN &&ct>0){ cir1((screenHeight-x1), (screenHeight-y1),x);

x1=x; y1=y; }

else if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) exit(0);

voiddoit ( void ){ glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); cir1(150,150,50); glEnd(); glFlush(); }

int main ( intargc, char** argv ){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(640,480); glutInitWindowPosition(100, 150); glutCreateWindow ( argv[0] );

init ( ); glutMouseFunc ( doMouse ); glutDisplayFunc(doit ); glutMainLoop ( ); return 0; }

Output:

You might also like