-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram13.c
More file actions
42 lines (37 loc) · 823 Bytes
/
Copy pathprogram13.c
File metadata and controls
42 lines (37 loc) · 823 Bytes
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
// write a c program for Generating Fractal images
#include <graphics.h>
#include <conio.h>
#include <math.h>
#define WIDTH 800
#define HEIGHT 600
#define MAX_ITER 1000
#define ZOOM 150
double x,y,r,temp,iVal;
int it;
int mandelbrot(double r, double i) {
x = 0.0, y = 0.0;
it = 0;
while (x*x + y*y <= 4.0 && it < MAX_ITER) {
temp = x*x - y*y + r;
y = 2*x*y + i;
x = temp;
it++;
}
return it;
}
int main() {
int gd = DETECT, gm, color, i, j;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
for (i = 0; i < WIDTH; i++) {
for (j = 0; j < HEIGHT; j++) {
r = (i - WIDTH / 2.0) / ZOOM;
iVal = (j - HEIGHT / 2.0) / ZOOM;
it = mandelbrot(r, iVal);
color = (it == MAX_ITER) ? 0 : (it % 256);
putpixel(i, j, color);
}
}
getch();
closegraph();
return 0;
}