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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147 | // C++ implementation for mandelbrot set fractals
#include <GL/glut.h>
#include <graphics.h>
#include <stdio.h>
// #define MAXCOUNT 30
#define MAXCOUNT 100
// Function to draw mandelbrot set
void fractal(float left, float top, float xside, float yside) {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
float xscale, yscale, zx, zy, cx, tempx, cy;
int x, y, i, j;<--- Unused variable: i<--- Unused variable: j
int maxx, maxy, count;
// getting maximum value of x-axis of screen
maxx = getmaxx();
// getting maximum value of y-axis of screen
maxy = getmaxy();
// setting up the xscale and yscale
xscale = xside / maxx;
yscale = yside / maxy;
// calling rectangle function
// where required image will be seen
rectangle(0, 0, maxx, maxy);
// scanning every point in that rectangular area.
// Each point represents a Complex number (x + yi).
// Iterate that complex number
for (y = 1; y <= maxy - 1; y++) {
for (x = 1; x <= maxx - 1; x++) {
// c_real
cx = x * xscale + left;
// c_imaginary
cy = y * yscale + top;
// z_real
zx = 0;
// z_imaginary
zy = 0;
count = 0;
// Calculate whether c(c_real + c_imaginary) belongs
// to the Mandelbrot set or not and draw a pixel
// at coordinates (x, y) accordingly
// If you reach the Maximum number of iterations
// and If the distance from the origin is
// greater than 2 exit the loop
while ((zx * zx + zy * zy < 4) && (count < MAXCOUNT)) {
// Calculate Mandelbrot function
// z = z*z + c where z is a complex number
// tempx = z_real*_real - z_imaginary*z_imaginary +
// c_real
tempx = zx * zx - zy * zy + cx;
// 2*z_real*z_imaginary + c_imaginary
zy = 2 * zx * zy + cy;
// Updating z_real = tempx
zx = tempx;
// Increment count
count = count + 1;
}
// To display the created fractal
putpixel(x, y, count);
}
}
glEnd();
glFlush();
}
void display() {
float left, top, xside, yside;
left = -1.74;
top = -0.25;
xside = 0.25;
yside = 0.45;
fractal(left, top, xside, yside);
}
// Driver code
int main(int argc, char **argv) {
// gm is Graphics mode which is
// a computer display mode that
// generates image using pixels.
// DETECT is a macro defined in
// "graphics.h" header file
int gd = DETECT, gm, errorcode;<--- Unused variable: errorcode
float left, top, xside, yside;
// setting the left, top, xside and yside
// for the screen and image to be displayed
/*
left = -1;
top = 0;
xside = 0;
yside = 0.2;
*/
left = -1.74;<--- Variable 'left' is assigned a value that is never used.
top = -0.25;<--- Variable 'top' is assigned a value that is never used.
xside = 0.25;<--- Variable 'xside' is assigned a value that is never used.
yside = 0.45;<--- Variable 'yside' is assigned a value that is never used.
char driver[] = "";
// initgraph initializes the
// graphics system by loading a
// graphics driver from disk
initgraph(&gd, &gm, driver);
// glutInit(&gd, driver);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(1366, 768);
glutInitWindowPosition(0, 0);
// Function calling
// fractal(left, top, xside, yside);
// getch();
// closegraph function closes the
// graphics mode and deallocates
// all memory allocated by
// graphics system
// closegraph();
glutCreateWindow("Mandelbrot Fractals with openGL");
glutDisplayFunc(display);
glutMainLoop();
getch();
return 0;
}
|