-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiamonds.cpp
61 lines (52 loc) · 1.34 KB
/
Diamonds.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
//Author: Kassim Izuagbe;
//Purpose: Generates a collection of diamonds at random locations;
#include <GL/glut.h>
#include <math.h>
#include <stdlib.h>
class GLintPoint
{
public:
GLint x, y;
};
void init(void)
{
glClearColor (1.0, 1.0, 1.0, 0.0);
glMatrixMode (GL_PROJECTION);
gluOrtho2D (-50.0, 300.0, -50.0, 300.0);
}
void drawDiamond(GLintPoint center, GLint length)
{
glBegin (GL_LINE_LOOP);
glVertex2i(((center.x)-(length/2)), center.y);
glVertex2i(center.x, ((center.y)-(length/2)));
glVertex2i(((center.x)+(length/2)), center.y);
glVertex2i(center.x, ((center.y)+(length/2)));
glEnd();
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 0.0, 0.0);
GLintPoint middle = {rand()%250, rand()%250};
GLint size = 89;
drawDiamond(middle, size);
for (int x = 0; x < size*2; x++)
{
GLintPoint middle = {rand()%250, rand()%250};
size = (rand()%89)+1;
drawDiamond(middle, size);
}
glFlush ();
}
int main(int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition (530, 290);
glutInitWindowSize (400, 400);
glutCreateWindow ("Equilateral Diamonds");
init ();
glutDisplayFunc (display);
glutMainLoop ( );
return 0;
}