-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
79 lines (60 loc) · 1.49 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdio.h>
#include "bitmap.h"
#define LIMIT 1.7
#define STEP 2 * LIMIT / DIM
#define DEPTH 512
/// struct for complex number representation
/// x is a real component of the number
/// y is an imaginary component of the number
struct complexNumber
{
double x;
double y;
};
struct complexNumber z0;
struct complexNumber z;
struct complexNumber c;
struct complexNumber tmp;
void numberInput()
{
printf("Enter the constant: ");
scanf("%lf %lf", &c.x, &c.y);
}
struct complexNumber addNumbers(struct complexNumber sum1, struct complexNumber sum2)
{
struct complexNumber sum;
sum.x = sum1.x + sum2.x;
sum.y = sum1.y + sum2.y;
return sum;
}
struct complexNumber multiplyNumbers(struct complexNumber mul1, struct complexNumber mul2)
{
struct complexNumber mul;
mul.x = mul1.x * mul2.x - mul1.y * mul2.y;
mul.y = mul1.y * mul2.x + mul1.x * mul2.y;
return mul;
}
unsigned char picture[DIM][DIM];
int main()
{
int i, j;
double re, im;
int n;
numberInput();
for (i = 0; i < DIM; i++) {
re = i * STEP - LIMIT;
for (j = 0; j < DIM; j++) {
im = j * STEP - LIMIT;
z0.x = im;
z0.y = re;
n = 0;
while (n < DEPTH && (z0.x * z0.x + z0.y * z0.y) < 4) {
z0 = addNumbers(multiplyNumbers(z0, z0), c);
n++;
}
picture[i][j] = (int)((255 * n) / DEPTH);
}
}
bmpOut(picture, "fractal.bmp");
return 0;
}