-
Notifications
You must be signed in to change notification settings - Fork 6
/
02. Flag_design.cpp
executable file
·151 lines (121 loc) · 3.56 KB
/
02. Flag_design.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <Windows.h>
#include <GL\glew.h>
#include <GL\freeglut.h>
#include <iostream>
#include <math.h>
#define HEIGHT 600
#define WIDTH 600
unsigned char matrix[HEIGHT][WIDTH][3]; // r,g,b
double offset=0;
void init()
{
int i,j;
//stick
for(i=50;i<500;i++)
for(j=25;j<50;j++)
{
matrix[i][j][0] = 139; // red
matrix[i][j][1] = 69; // green
matrix[i][j][2] = 19; // blue
}
for(i=350;i<400;i++)
for(j=50;j<275;j++) // 2:3 ratio flag
{
matrix[i][j][0] = 0; // red
matrix[i][j][1] = 255; // green
matrix[i][j][2] = 0; // blue
}
for(i=400;i<450;i++)
for(j=50;j<275;j++)
{
matrix[i][j][0] = 255; // red
matrix[i][j][1] = 255; // green
matrix[i][j][2] = 255; // blue
}
for(i=450;i<500;i++)
for(j=50;j<275;j++)
{
matrix[i][j][0] = 255; // red
matrix[i][j][1] = 153; // green
matrix[i][j][2] = 51; // blue
}
glClearColor(0,0,0.4,0);
glOrtho(-1,1,-1,1,-1,1);
}
void DrawCircle(float cx, float cy, float r, int num_segments)
{
glBegin(GL_LINE_LOOP);
glColor3d(0,0,255);
for(int ii = 0; ii < num_segments; ii++)
{
float theta = 2.0f * 3.1415926f * float(ii) / float(num_segments);//get the current angle
float x = r * cosf(theta);//calculate the x component
float y = r * sinf(theta);//calculate the y component
glVertex2f(x + cx, y + cy);//output vertex
}
glEnd();
}
void DrawLines(float cx, float cy, float r, int num_segments)
{
glBegin(GL_LINE_LOOP);
glColor3d(0,0,255);
for(int ii = 0; ii < num_segments; ii++)
{
float theta = 2.0f * 3.1415926f * float(ii) / float(num_segments);//get the current angle
float x = r * cosf(theta);//calculate the x component
float y = r * sinf(theta);//calculate the y component
glVertex2f(x + cx, y + cy);//output vertex
glBegin(GL_LINES);
glVertex2f(-0.48, 0.415);
}
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glDrawPixels(WIDTH,HEIGHT,GL_RGB,GL_UNSIGNED_BYTE,matrix);
DrawCircle(-0.48,0.415,0.07,200);
DrawLines(-0.48,0.415,0.07,24);
glutSwapBuffers();
}
void idle()
{
static float count = 0.0;
int i,j;
count += 0.05;
offset-=0.14;
for(i=350;i<400;i++)
for(j=50;j<275;j++)
{
matrix[i][j][0] = 0; // red
matrix[i][j][1] = 230 + 25 * sin(count + j * 0.02); // green
matrix[i][j][2] = 0; // blue
}
for(i=400;i<450;i++)
for(j=50;j<275;j++)
{
matrix[i][j][0] = 230 + 25 * sin(count + j * 0.02); // red
matrix[i][j][1] = 230 + 25 * sin(count + j * 0.02); // green
matrix[i][j][2] = 230 + 25 * sin(count + j * 0.02); // blue
}
for(i=450;i<500;i++)
for(j=50;j<275;j++)
{
matrix[i][j][0] = 230 + 25 * sin(count + j * 0.02); // red
matrix[i][j][1] = 128 + 25 * sin(count + j * 0.02); // green
matrix[i][j][2] = 26 + 25 * sin(count + j * 0.02); // blue
}
glutPostRedisplay();
}
void main( int argc, char* argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE);
glutInitWindowSize(WIDTH,HEIGHT);
glutInitWindowPosition(100,100);
glutCreateWindow("FLAG");
glutDisplayFunc(display);
glutIdleFunc(idle);
init();
glutMainLoop();
}