-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrumah.cpp
More file actions
100 lines (90 loc) · 2.66 KB
/
rumah.cpp
File metadata and controls
100 lines (90 loc) · 2.66 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
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
#include <windows.h>
#include <GL/glut.h>
#include <ctime>
#include <cmath>
void randomColor () {
glColor3f (static_cast <float> (rand()) / static_cast <float> (RAND_MAX),
static_cast <float> (rand()) / static_cast <float> (RAND_MAX),
static_cast <float> (rand()) / static_cast <float> (RAND_MAX));
}
void drawQuad (int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
glBegin (GL_QUADS);
randomColor ();
glVertex2i (x1, y1);
glVertex2i (x2, y2);
glVertex2i (x3, y3);
glVertex2i (x4, y4);
glEnd();
glBegin (GL_LINE_LOOP);
glColor3f (0.0f, 0.0f, 0.0f);
glVertex2i (x1, y1);
glVertex2i (x2, y2);
glVertex2i (x3, y3);
glVertex2i (x4, y4);
glEnd();
}
void drawQuad (int xl, int xr, int yl, int yu) {
drawQuad (xl, yl, xr, yl, xr, yu, xl, yu);
}
void drawTriangle (int u, int b, int l, int r) {
glBegin (GL_TRIANGLES);
randomColor ();
glVertex2i ((l + r) / 2, u);
glVertex2i (l, b);
glVertex2i (r, b);
glEnd ();
glBegin (GL_LINE_LOOP);
glColor3f (0.0f, 0.0f, 0.0f);
glVertex2i ((l + r) / 2, u);
glVertex2i (l, b);
glVertex2i (r, b);
glEnd();
}
void drawCircle (int r, int jumlah_titik, int x_center, int y_center) {
const double PI = 3.141592653589793;
glBegin (GL_POLYGON);
randomColor ();
for (int i = 0; i <= 360; i++) {
double sudut = i * (2 * PI / jumlah_titik);
double x = x_center + r * cos (sudut);
double y = y_center + r * sin (sudut);
glVertex2d (x, y);
}
glEnd();
}
void drawDotCircle (int r, int jumlah_titik, int x_center, int y_center) {
const double PI = 3.141592653589793;
for (int i = 0; i <= 360; i++) {
glBegin (GL_POINTS);
double sudut = i * (2 * PI / jumlah_titik);
double x = x_center + r * cos (sudut);
double y = y_center + r * sin (sudut);
glVertex2d (x, y);
}
glEnd();
}
void display () {
glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
glClear (GL_COLOR_BUFFER_BIT);
drawQuad (20, 60, 20, 60);
drawQuad (60, 130, 20, 60);
drawTriangle (90, 60, 20, 60);
drawQuad (40, 90, 60, 60, 130, 60, 110, 90);
drawQuad (30, 50, 20, 45);
drawQuad (75, 115, 30, 50);
drawCircle (10, 360, 20, 130);
drawDotCircle (13, 16, 20, 130);
glFlush ();
}
int main (int argc, char** argv) {
srand (static_cast <unsigned> (time (0)));
glutInit (&argc, argv);
glutCreateWindow ("roemah");
glutInitWindowSize (640, 640);
glutInitWindowPosition (50, 50);
gluOrtho2D (0.0, 150.0, 0.0, 150.0);
glPointSize (2.0);
glutDisplayFunc (display);
glutMainLoop ();
return 0;
}