-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
115 lines (93 loc) · 2.28 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
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
#include "render/render_brute_force.h"
#include "render/render_perimeter.h"
#include "image.h"
static char *int_to_binary(__uint32_t n)
{
char *name = malloc(33 * sizeof(char));
for(int i = 0; i < 32; i++)
{
if(n & 1)
{
name[32 - i - 1] = '1';
}
else
{
name[32 - i - 1] = '0';
}
n = n >> 1;
}
name[32] = '\0';
return name;
}
static unsigned int mandelbrot_2(double init_x,
double init_y,
int max_iterations)
{
unsigned int i = 1;
double x = 0;
double y = 0;
while(i < max_iterations)
{
double new_x = x * x - y * y + init_x;
double new_y = 2 * x * y + init_y;
x = new_x;
y = new_y;
if(x > 2 || y > 2)
{
return i;
}
i++;
}
return 0;
}
static unsigned int mandelbrot_3(double init_x,
double init_y,
int max_iterations)
{
unsigned int i = 1;
double x = 0;
double y = 0;
while(i < max_iterations)
{
double new_x = x * x * x - 3 * x * y * y + init_x;
double new_y = 3 * x * x * y - y * y * y + init_y;
x = new_x;
y = new_y;
if(x > 2 || y > 2)
{
return i;
}
i++;
}
return 0;
}
static void fractal_to_bitmap(fractal_t *fractal,
bitmap_t *bitmap)
{
for(int y = 0; y < fractal->height; y++)
{
for(int x = 0; x < fractal->width; x++)
{
if(get_pixel_perimeter(fractal, x, y))
{
set_pixel(bitmap, x, y, 0xFF0000);
}
else
{
set_pixel(bitmap, x, y, get_pixel_value(fractal, x, y) * 512 + 0x00FF00);
}
}
}
}
int main()
{
fractal_t *fractal = new_fractal(10000, 10000, -2.5, -1.5, .5, 1.5);
bitmap_t *bitmap = new_bitmap(10000, 10000);
render_t *render = new_render(mandelbrot_2, 65536, 4);
render_fractal_perimeter(fractal, render);
fractal_to_bitmap(fractal, bitmap);
save_png_to_file(bitmap, "outline.png");
free_fractal(fractal);
free_bitmap(bitmap);
free_render(render);
}