#include <windows.h>
#include <gl/gl.h>
#include <gl/glut.h>
#include <math.h>
using namespace std;
void Ok();
void Set_Transformations();
void Initialize(int argc, char *argv[]);
void OnKeyPress(unsigned char key, int x, int y);
void Draw(int number);
void Draw_Big_Circle(double radius, double x, double y);
void Draw_Black_Circle(double radius2,double x2, double y2);
void Draw_White_Circle(double radius3,double x3, double y3);
const float DEG2RAD = 3.141592653/180;
int main(int argc, char *argv[]) {
Initialize(argc, argv);
return 0;
}
void Initialize(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(500, 500);
glutCreateWindow("Part One -Press(1)for ChessBoard--(2)for Yin-Yang symbol");
Set_Transformations();
glutDisplayFunc(Ok);
glutKeyboardFunc(OnKeyPress);
glutMainLoop();
}
void Set_Transformations() {
glClearColor(1.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-100, 100, -100, 100);
glMatrixMode(GL_MODELVIEW);
}
void Draw(int number){
glClear(GL_COLOR_BUFFER_BIT);
switch(number){
case 1:
glBegin(GL_LINE_LOOP); glColor3f(0.0,0.0,0.0);
glVertex2f(0, 80);
glVertex2f(80, 80);
glVertex2f(80, 0);
glVertex2f(0, 0);
glEnd();
glBegin(GL_QUADS);
glColor3f(0.6,0.6,0.6);
for(int x=0; x<8; x++)
for(int y=0; y<8; y++)
if((x+y)%20)
{ glVertex2f(x, y);
glVertex2f(x+1, y);
glVertex2f(x+1, y+1);
glVertex2f(x, y+1);
}
glEnd();
break;
case 2:
Draw_Big_Circle(50,5,25);
Draw_Black_Circle(25,5,50);
Draw_White_Circle(25,5,0);
Draw_Black_Circle(5,5,0);
Draw_White_Circle(5,5,50);
glEnd();
break;
}
glFlush();
}
void Draw_Big_Circle(double radius, double x, double y){
glColor3f(0.0f, 0.0f, 0.0f);
glBegin(GL_TRIANGLE_FAN);
for (int angle = 0; angle <= 180; angle++){
float degInRad = angle*DEG2RAD;
glVertex2f((float)(x + sin(degInRad) * radius),
(float)(y + cos(degInRad) * radius));
}
glEnd();
glLineWidth(1.0f);
glColor3d(0.0, 0.0, 0.0);
glBegin(GL_POINTS);
for (float angle = 0; angle <= 360; angle += 0.05){
float degInRad = angle*DEG2RAD;
glVertex2f((float)(x + sin(degInRad) * radius),
(float)(y + cos(degInRad) * radius));
}
glEnd();
}
void Draw_Black_Circle(double radius2,double x2, double y2){
glColor3f(0.0f, 0.0f, 0.0f);
glBegin(GL_TRIANGLE_FAN);
for (int angle = 0; angle <= 360; angle++){
float degInRad = angle*DEG2RAD;
glVertex2f((float)(x2 + sin(degInRad) * radius2),
(float)(y2 + cos(degInRad) * radius2));
}
glEnd();
}
void Draw_White_Circle(double radius3,double x3, double y3){
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_TRIANGLE_FAN);
for (int angle = 0; angle <= 360; angle++){
float degInRad = angle*DEG2RAD;
glVertex2f((float)(x3 + sin(degInRad) * radius3),
(float)(y3 + cos(degInRad) * radius3));
}
glEnd();
}
void Ok(){
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void OnKeyPress(unsigned char key, int x, int y)
{
if(key == 27)
{
exit(0);
}
switch(key)
{
case '1':
Draw(1);
break;
case '2':
Draw(2);
break;
}
}