Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <windows.h>
#include <gl/gl.h>
#include <gl/glut.h>
#include <math.h>
using namespace std;


// initializations
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); //border
			glColor3f(0.0,0.0,0.0);
			glVertex2f(0, 80);
			glVertex2f(80, 80);
			glVertex2f(80, 0);
			glVertex2f(0, 0);
			glEnd();
			
			glBegin(GL_QUADS); //here the chess 
			
			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){ 
	//Polygon
	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();

	//Border 
	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){

	//Polygon
	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){

	//Polygon
	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;
	}
}
Posted
Updated 31-Mar-14 20:06pm
v2
Comments
Rage 1-Apr-14 3:44am    
What do you mean with "big" and "small" ?
Shta 3-Apr-14 7:43am    
near or far !
Rage 3-Apr-14 7:53am    
Change the camera position ?
Shta 25-Apr-14 8:13am    
done and it works .. sorry for replying that late..
Member 11669411 6-May-15 10:44am    
how did you correct it ?!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900