void OGWindow::drawGrid(GLvoid){
int squareColour = 1;
int size = 7;
srand(time(NULL));
for (int xValue = 0; xValue < size; xValue++)
{
for (int yValue = 0; yValue < size; yValue++)
{
if (xValue == 0 && yValue == 0)
{
glColor3f(1, 0, 0);
//start square
glBegin(GL_QUADS);
glVertex3f(xValue-0.3, yValue-0.3, 0.0);
glVertex3f(xValue+0.3, yValue-0.3, 0.0);
glVertex3f(xValue+0.3, yValue+0.3, 0.0);
glVertex3f(xValue-0.3, yValue+0.3, 0.0);
glEnd();
glColor3f(0, 0, 0);
//start square outline
glBegin(GL_LINE_LOOP);
glVertex3f(xValue-0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue+0.5, 0.0);
glVertex3f(xValue-0.5, yValue+0.5, 0.0);
glEnd();
} else if (xValue == size - 2 && yValue == size - 2){
glColor3f(0, 0, 1);
//an end square
glBegin(GL_QUADS);
glVertex3f(xValue-0.3, yValue-0.3, 0.0);
glVertex3f(xValue+0.3, yValue-0.3, 0.0);
glVertex3f(xValue+0.3, yValue+0.3, 0.0);
glVertex3f(xValue-0.3, yValue+0.3, 0.0);
glEnd();
glColor3f(0, 0, 0);
//end square outline
glBegin(GL_LINE_LOOP);
glVertex3f(xValue-0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue+0.5, 0.0);
glVertex3f(xValue-0.5, yValue+0.5, 0.0);
glEnd();
} else {
glColor3f(0, 0, 0);
//square outline
glBegin(GL_LINE_LOOP);
glVertex3f(xValue-0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue+0.5, 0.0);
glVertex3f(xValue-0.5, yValue+0.5, 0.0);
glEnd();
int random = rand() % 5;
cout << random << endl;
if (random < 2){
squareColour = 0;
}else{
squareColour = 1;
}
glColor3f(squareColour, squareColour, squareColour);
//making a square
glBegin(GL_QUADS);
glVertex3f(xValue-0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue+0.5, 0.0);
glVertex3f(xValue-0.5, yValue+0.5, 0.0);
glEnd();
}
}
}
} |