ODD One out Quiz

Saturday, 8 March 2014

Tic Tac Toe Game Designed in Graphics

Code of Tic Tac Toe Game in Graphics in OpenGL


#include<GL/gl.h>
#include<GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0,1.0,0.0,0.0);
glLineWidth(10.0);
glBegin(GL_LINES);
glColor3f(1.0,1.0,0.0);
glVertex2f(-0.70,0.2);
glVertex2f(0.70,0.2);
glVertex2f(-0.70,-0.30);
glVertex2f(0.70,-0.30);
glEnd();
glBegin(GL_LINES);
glColor3f(1.0,1.0,0.0);
glVertex2f(0.30,-0.70);
glVertex2f(0.30,0.70);
glVertex2f(-0.20,-0.70);
glVertex2f(-0.20,0.70);
glEnd();
int num_segments=150;
int i;
  

float cx=-0.45,cy=0.40, r=0.15;
  
  glColor3f(1.0,0.0,1.0);
  
  glBegin(GL_LINE_LOOP);
  
for(i=0;i<num_segments;i++)
{
       float theta;
theta=(2.0*3.1415962*(i))/(num_segments);
float x=r*cosf(theta);
float y=r*sinf(theta);
glVertex2f(x+cx,y+cy);
}
glEnd();
  
//glLineWidth(15.0);
glBegin(GL_LINES);
glColor3f(0.0,0.0,0.0);
glVertex2f(-0.10,0.60);
glVertex2f(0.20,0.30);
glVertex2f(0.20,0.60);
glVertex2f(-0.10,0.30);
glEnd();
glBegin(GL_LINES);
glColor3f(0.0,0.0,0.0);
glVertex2f(0.40,0.60);
glVertex2f(0.65,0.30);
glVertex2f(0.65,0.60);
glVertex2f(0.40,0.30);
glEnd();
glBegin(GL_LINES);
glColor3f(0.0,0.0,0.0);
glVertex2f(-0.60,-0.20);
glVertex2f(-0.30,0.10);
glVertex2f(-0.30,-0.20);
glVertex2f(-0.60,0.10);
glEnd();
glBegin(GL_LINES);
glColor3f(0.0,0.0,0.0);
glVertex2f(-0.60,-0.70);
glVertex2f(-0.30,-0.40);
glVertex2f(-0.60,-0.40);
glVertex2f(-0.30,-0.70);
glEnd();

float cx1=0.05,cy1=-0.50;
  
 // glColor3f(1.0,0.0,1.0);
  
  glBegin(GL_LINE_LOOP);
for(i=0;i<num_segments;i++)
{
       float theta;
theta=(2.0*3.1415962*(i))/(num_segments);
float x=r*cosf(theta);
float y=r*sinf(theta);
glVertex2f(x+cx1,y+cy1);
}
glEnd();
  
float cx2=0.50,cy2=-0.50;// 9th Circle
  
 // glColor3f(0.0,0.0,0.0);
  glColor3f(1.0,0.0,1.0);
  glBegin(GL_LINE_LOOP);
for(i=0;i<num_segments;i++)
{
       float theta;
theta=(2.0*3.1415962*(i))/(num_segments);
float x=r*cosf(theta);
float y=r*sinf(theta);
glVertex2f(x+cx2,y+cy2);
}
glEnd();
float cx3=0.50,cy3=-0.05;
  
  glColor3f(0.0,0.0,0.0);
  
  glBegin(GL_LINE_LOOP);
for(i=0;i<num_segments;i++)
{
       float theta;
theta=(2.0*3.1415962*(i))/(num_segments);
float x=r*cosf(theta);
float y=r*sinf(theta);
glVertex2f(x+cx3,y+cy3);
}
glEnd();
float cx4=0.05,cy4=-0.05;
  //glColor3f(0.0,0.0,0.0);
  
  glColor3f(1.0,0.0,1.0);
  glBegin(GL_LINE_LOOP);
for(i=0;i<num_segments;i++)
{
       float theta;
theta=(2.0*3.1415962*(i))/(num_segments);
float x=r*cosf(theta);
float y=r*sinf(theta);
glVertex2f(x+cx4,y+cy4);
}
glEnd();
glFlush();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(150,150);
glutCreateWindow("Displaying Tic Tac Toe");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}





No comments:

Post a Comment