-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
99 lines (86 loc) · 2.3 KB
/
main.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
#include <GL/glut.h>
#include <cmath>
// Circle
void circle(float x, float y, float radius, float glTranslatefX, float glTranslatefY, float glTranslatefZ, int red,
int green, int blue)
{
double p = 0.0;
double q = 0.0;
double angle = 1.0;
glPushMatrix();
glTranslatef(glTranslatefX, glTranslatefY, glTranslatefZ);
glColor3f(red, green, blue);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(p, q);
while (true)
{
if (angle <= 360)
{
p = x + sin(angle) * radius;
q = y + cos(angle) * radius;
glVertex2f(p, q);
}
else
{
break;
}
angle += 0.1;
}
glEnd();
glPopMatrix();
}
// Display
void display()
{
// Middle Circle
circle(0.0, 0.0, 0.25,
0, 0, 0,
1, 1, 1);
// Up Circle
circle(0.0, 0.0, 0.25,
0, 0.5, 0,
1, 0, 0);
// Down Circle
circle(0.0, 0.0, 0.25,
0, -0.5, 0,
0, 1, 0);
// Up Left Circle
circle(0.0, 0.0, 0.25,
-0.425, 0.25, 0,
0, 0, 1);
// Up Right Circle
circle(0.0, 0.0, 0.25,
0.425, 0.25, 0,
1, 1, 0);
// Down Left Circle
circle(0.0, 0.0, 0.25,
-0.425, -0.25, 0,
1, 0, 1);
// Right Right Circle
circle(0.0, 0.0, 0.25,
0.425, -0.25, 0,
0, 1, 1);
glFlush(); // Render Now
}
// Initialization
void initialize()
{
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
}
// Main
int main(int argc, char *argv[])
{
glutInit(&argc, argv); // Initialize GLUT
int x = 512, y = 512; // x and y value
glutInitWindowPosition(
(int)(glutGet(GLUT_SCREEN_WIDTH) - x) / 2,
(int)(glutGet(GLUT_SCREEN_HEIGHT) - y) / 2); // Position the window's center
glutInitWindowSize(x, y); // Set the window's initial width & height
glutCreateWindow("Flower Shape Circle"); // Create a window with the given title
initialize(); // Initializing
glutDisplayFunc(display); // Register display callback handler for window re-paint
glutMainLoop(); // Enter the event-processing loop
return 0;
}
// End