-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmandelbrot.c
49 lines (45 loc) · 1.59 KB
/
mandelbrot.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
#include "stdio.h"
#include "stdlib.h"
// This function will be available in the DLL.
EXPORT void __stdcall mandelbrot(int size,
int iterations,
int *col)
int main(void)
{
// Variable declarations.
int i, j, n, index;
double cx, cy;
double z0, z1, z0_tmp, z0_2, z1_2;
// Loop within the grid.
for (i = 0; i < size; i++)
{
cy = -1.5 + (double)i / size * 3;
for (j = 0; j < size; j++)
{
// We initialize the loop of the
// system.
cx = -2.0 + (double)j / size * 3;
index = i * size + j;
// Let's run the system.
z0 = 0.0;
z1 = 0.0;
for (n = 0; n < iterations; n++)
{
z0_2 = z0 * z0;
z1_2 = z1 * z1;
if (z0_2 + z1_2 <= 100)
{
// Update the system.
z0_tmp = z0_2 - z1_2 + cx;
z1 = 2 * z0 * z1 + cy;
z0 = z0_tmp;
col[index] = n;
}
else
{
break;
}
}
}
}
}