-
Notifications
You must be signed in to change notification settings - Fork 3
/
cantor_set.c
66 lines (53 loc) · 1.54 KB
/
cantor_set.c
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
/* Author: NagaChaitanya Vellanki */
#include <GLFW/glfw3.h>
void cantor_set(float x, float y, float length) {
glColor4f(0.5f, 1.0f, 0.0f, 1.0f);
glLineWidth(5.0f);
glBegin(GL_LINES);
glVertex2f(x, y);
glVertex2f(x + length, y);
glEnd();
y -= 20.0f;
if(length > 1.0f) {
cantor_set(x, y, length / 3);
cantor_set(x + 2 * (length / 3), y, length / 3);
}
}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
}
int main(int argc, char *argv[]) {
GLFWwindow* window;
if(!glfwInit()) {
return -1;
}
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* vidmode = glfwGetVideoMode(monitor);
window = glfwCreateWindow(vidmode->width, vidmode->height, "Cantor Set", monitor, NULL);
if(!window) {
glfwTerminate();
return -1;
}
glfwSetKeyCallback(window, key_callback);
glfwMakeContextCurrent(window);
int width, height;
glfwGetFramebufferSize(window, &width, &height);
float x = 0.0f;
float y = height / 2;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, width, 0.0f, height, 0.0, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
while(!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT);
cantor_set(x, y, width);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}