-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcircle.cpp
More file actions
60 lines (51 loc) · 1.58 KB
/
circle.cpp
File metadata and controls
60 lines (51 loc) · 1.58 KB
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
#include <GL/glut.h>
#include <cmath>
int theta = 0;
int blueHex = 0;
int blueHexChangeSpeed = 4;
void draw_circle (int r, int jumlah_titik, int x_center, int y_center) {
glBegin (GL_POLYGON);
for (int i = 0; i <= jumlah_titik; i++){
double sudut = i * (2 * M_PI / jumlah_titik);
float x = x_center + r * cos (sudut);
float y = y_center + r * sin (sudut);
glVertex2f (x, y);
}
glEnd();
}
void renderScene () {
glClear (GL_COLOR_BUFFER_BIT);
theta = (theta + 1) % 360;
blueHex = (blueHex + blueHexChangeSpeed);
if (blueHex == 100 || blueHex == 0)
// reverse blue hex cycle direction
blueHexChangeSpeed *= -1;
double rad = theta * M_PI / 180;
glColor3f (1.0, 0.0, 0.0); // red
draw_circle (30, 100, 200 * cos (rad), sin (rad) * 200);
glColor3f (0.0, 0.0, blueHex / 100.0); // blue
draw_circle (100, 100, 0, 0);
glFlush ();
}
void idle () {
static int lastTime = 0;
int time = glutGet (GLUT_ELAPSED_TIME);
if (lastTime == 0 || time >= lastTime + 50) {
lastTime = time;
glutPostRedisplay ();
}
}
void visible (int vis) {
glutIdleFunc (vis == GLUT_VISIBLE ? idle : nullptr);
}
int main (int argc, char** argv) {
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize (640, 480);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Lingkaran Berputar v:");
gluOrtho2D (-320.0, 320.0, -240.0, 240.0);
glutDisplayFunc (renderScene);
glutVisibilityFunc (visible);
glutMainLoop ();
}