Hello guys , I just wrote a code of Cellular Automata using OpenGl
but I need your help in converting this code to a C++ code
here is the code :

#include <windows.h>
#include <math.h>
#include <gl/Gl.h>
#include <gl/Glu.h>
#include <gl/glut.h>
#include<iostream>
#include<cstdlib>
using namespace std;
GLsizei Height= 800;
GLsizei Width= 600;
#define WAIT 1000
int  i,j,b[50][50]={0},a[50][50]={0},count=0;

void Display()
{
	glColor3f(0,0,0);
	glClear(GL_COLOR_BUFFER_BIT);
	for(i=1;i<49;i++)
		for( j=1;j<49;j++)
		{
			count=0;
			if(b[i-1][j+1]==1)
				count++;
			if(b[i-1][j]==1)
				count++;
			if(b[i-1][j-1]==1)
				count++;
			if(b[i][j+1]==1)
				count++;
			if(b[i][j-1]==1)
				count++;
			if(b[i+1][j+1]==1)
				count++;
			if(b[i+1][j]==1)
				count++;
			if(b[i+1][j-1]==1)
				count++;

			if(a[i][j]==1)
			{
				glColor3f(1,0,0);
				glBegin(GL_POLYGON);
				glVertex2f(i*10, j*10);
				glVertex2f((i*10)+10,j*10);
				glVertex2f((i*10)+10, (j*10)+10);
				glVertex2f(i*10, (j*10)+10);
				glVertex2f(i*10, j*10);
				glEnd();
				

			}
			else if(a[i][j]==0)
			{
				glColor3f(0,0,0);
				glBegin(GL_LINE_STRIP);
				glVertex2f(i*10,j*10);
				glVertex2f((i*10)+10,j*10);
				glVertex2f((i*10)+10, (j*10)+10);
				glVertex2f(i*10, (j*10)+10);
				glVertex2f(i*10, j*10);
				glEnd();
			}
			if(b[i][j]==0&&count==3)
			{
				a[i][j]=1;	
			}
			else if(b[i][j]==1&&(count==0||count==1||count>=4))
			{
				a[i][j]=0;		
			}
			else if(b[i][j]==0&&count!=3)
				a[i][j]=0;
			else if(b[i][j]==1&&(count==3||count==2))
				a[i][j]=1;
			if(i==48&&j==48)
				for(i=1;i<49;i++)
					for( j=1;j<49;j++)
					{
						b[i][j]=a[i][j];
					}				
		}
		glFlush();
}
void myReshape (int w, int h)
{
	glViewport (0, 0, (GLsizei) w, (GLsizei) h);
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	gluOrtho2D (0.0, (GLdouble)w , 0.0, (GLdouble) h);
	Height=h;
	Width=w;

}

void myinit(int red,int green,int blue)
{
	glClearColor(red,green,blue,0.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, Width,0.0,Height);

}
void waitAndRedraw (int foo) 
{
	glutPostRedisplay();
	glutTimerFunc(WAIT,waitAndRedraw,0);
}

void main(int argc, char **argv)
{
	b[25][25]=1;
	b[26][25]=1;
	b[27][25]=1;
	b[25][26]=1;
	b[27][26]=1;
	b[25][27]=1;
	b[26][27]=1;
	b[27][27]=1;
	a[25][25]=1;
	a[26][25]=1;
	a[27][25]=1;
	a[25][26]=1;
	a[27][26]=1;
	a[25][27]=1;
	a[26][27]=1;
	a[27][27]=1;
	
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
	glutInitWindowPosition(100,100);
	glutInitWindowSize(Width, Height);
	glutCreateWindow("Artificial Intelligence");
	glutDisplayFunc(Display);
	glutReshapeFunc(myReshape);
	glutTimerFunc(WAIT,waitAndRedraw,0);
	myinit(1.0,1.0,1.0);
	glutMainLoop();
}
This article has been dead for over six months. Start a new discussion instead.