<commit_before>---
layout: post
title: Draw VN flag in OpenGL
description: "How to Draw VN flag in OpenGL?"
modified: 2015-05-12
tags: [OpenGL, cpp]
---
{% highlight cpp %}
#include<GL\glut.h>
#include<stdlib.h>
#include<math.h>
#include<windows.h>
#include<time.h>
float radian=3.1415/180;
int x=300;
int y=250;
float r=50;
int max=1000000;
void Init();
void Display();
void Reshape(int Width, int Height);
void Keyboard(unsigned char Key, int X, int Y);


void Init()
{
	glClearColor(0.0,0.0,0.0,0.0);
}
void Setpixel(double x,double y)
{
	glBegin(GL_POINTS);
	glVertex2f(x,y);
	glEnd();
}


void DINHNGOISAO(float tdx,float tdy,float r)
{
	glPointSize(5);
	glBegin(GL_POINTS);
	glColor3f(1.0,0.0,0.0);
	//5 dinh 
	glVertex2i(tdx,tdy+r);
	glVertex2f(tdx-r*cos(18*radian),tdy+r*cos(72*radian));
	glVertex2f(tdx+r*cos(18*radian),tdy+r*cos(72*radian));
	glVertex2f(tdx-r*cos(54*radian),tdy-r*cos(36*radian));
	glVertex2f(tdx+r*cos(54*radian),tdy-r*cos(36*radian));
	//2dinh giua tren
	glVertex2f(tdx-r*cos(72*radian)*tan(36*radian),tdy+r*cos(72*radian));
	glVertex2f(tdx+r*cos(72*radian)*tan(36*radian),tdy+r*cos(72*radian));
	//2dinh giua duoi
	glVertex2f(tdx-r*cos(72*radian)*cos(18*radian)/cos(36*radian),tdy-r*cos(72*radian)*sin(18*radian)/cos(36*radian));
	glVertex2f(tdx+r*cos(72*radian)*cos(18*radian)/cos(36*radian),tdy-r*cos(72*radian)*sin(18*radian)/cos(36*radian));
	//dinh cuoi
	glVertex2f(tdx,y-r*cos(72*radian)/cos(36*radian));
	glEnd();
	glPointSize(1);
	glColor3f(0.0,1.0,0.0);
//	Circle(tdx,tdy,r);
}
void NGOISAO(float tdx,float tdy,float r)
{
	glBegin(GL_POLYGON);
	glVertex2f(tdx-r*cos(72*radian)*tan(36*radian),tdy+r*cos(72*radian));
	glVertex2f(tdx-r*cos(18*radian),tdy+r*cos(72*radian));
	glVertex2f(tdx-r*cos(72*radian)*cos(18*radian)/cos(36*radian),tdy-r*cos(72*radian)*sin(18*radian)/cos(36*radian));
	glVertex2f(tdx-r*cos(54*radian),tdy-r*cos(36*radian));
	glVertex2f(tdx,y-r*cos(72*radian)/cos(36*radian));
	glVertex2f(tdx+r*cos(54*radian),tdy-r*cos(36*radian));
	glVertex2f(tdx+r*cos(72*radian)*cos(18*radian)/cos(36*radian),tdy-r*cos(72*radian)*sin(18*radian)/cos(36*radian));
	glVertex2f(tdx+r*cos(18*radian),tdy+r*cos(72*radian));
	glVertex2f(tdx+r*cos(72*radian)*tan(36*radian),tdy+r*cos(72*radian));
	glVertex2i(tdx,tdy+r);
	glVertex2f(tdx-r*cos(72*radian)*tan(36*radian),tdy+r*cos(72*radian));
	glEnd();
}
void HinhVuong(float tdx,float tdy,float r)
{
	glPointSize(5);
	glBegin(GL_POLYGON);
	glVertex2i(tdx-r-100,tdy+r+50);
	glVertex2i(tdx-r-100,tdy-r-50);
	glVertex2i(tdx+r+100,tdy-r-50);
	glVertex2i(tdx+r+100,tdy+r+50);
	glEnd();
}
void Display()
{
	glClear(GL_COLOR_BUFFER_BIT);
	DINHNGOISAO(x,y,r);
	glColor3f(1.0,0.0,0.0);
	HinhVuong(x,y,r);
	glColor3f(1.0,1.0,0.0);
	NGOISAO(x,y,r);
	glFlush();
}

void Reshape(int Width,int Height)
{
	glViewport(0,0,(GLsizei)Width,(GLsizei)Height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0,(GLdouble)Width-1,0.0,(GLdouble)Height-1);
}
void Keyboard(unsigned char Key,int X,int Y)
{
	switch(Key)
	{
	case 27:
		exit(EXIT_SUCCESS);
		break;
	case 114:
		r+=5;
		break;
	case 102:
		r-=5;
		break;
	case 97:
		x-=5;break;
	case 100:
		x+=5;break;
	case 119:
		y+=5;break;
	case 115:
		y-=5;break;
	}
	glutPostRedisplay();
}
void MyIdle()
{
	Sleep(200);
		//x = rand() %300+200;
		//y = rand() %300+200;
		//r = rand() %(100);
	glutPostRedisplay();
}
void main(int Argc,char **Argv)
{
	glutInit(&Argc,Argv);
	glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
	glutInitWindowSize(640,480);
	glutInitWindowPosition(0,0);
	glutCreateWindow("Test");
	Init();
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutKeyboardFunc(Keyboard);
	glutIdleFunc(MyIdle);
	glutMainLoop();
}
{% endhighlight %}<commit_msg>Update 2015-05-12-OpenGL-vn-flag.md<commit_after>---
layout: post
title: Draw VN flag in OpenGL
description: "How to Draw VN flag in OpenGL?"
modified: 2015-05-12
tags: [OpenGL, cpp]
---

abcd

{% highlight cpp %}

{% endhighlight %}
{'fraction_non_alphanumeric': 0.2072736520854527, 'fraction_numerical': 0.07960325534079349, 'mean_word_length': 7.059426229508197, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2996573', 'n_tokens_mistral': 2130, 'n_tokens_neox': 1940, 'n_words': 233}