Skip to content

Commit 45f207c

Browse files
committed
mandelbrot example
1 parent f6e45bb commit 45f207c

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

source/main.cpp

+28-3
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,41 @@ void display_julia(std::size_t width, std::size_t height, std::complex<double> c
5151
auto x_step = X_DIM * 2 / static_cast<double>(width);
5252
auto y_step = Y_DIM * 2 / static_cast<double>(height);
5353

54+
for (std::size_t j = 0; j < height; ++j) {
55+
for (std::size_t i = 0; i < width; ++i) {
56+
double x = -X_DIM + i * x_step;
57+
double y = -Y_DIM + j * y_step;
58+
59+
auto iterations = compute_iterations({x, y}, constant, MAX_ITERATIONS);
60+
61+
display.set_pixel(
62+
i, j,
63+
static_cast<int>(iterations / static_cast<double>(MAX_ITERATIONS) * 255)
64+
);
65+
}
66+
}
67+
68+
display.display_window();
69+
}
70+
71+
void display_mandelbrot(
72+
std::size_t width, std::size_t height, std::complex<double> constant
73+
)
74+
{
75+
fractal::BasicDisplay display;
76+
77+
auto x_step = X_DIM * 2 / static_cast<double>(width);
78+
auto y_step = Y_DIM * 2 / static_cast<double>(height);
79+
5480
for (std::size_t j = 0; j < height; ++j) {
5581
for (std::size_t i = 0; i < width; ++i) {
5682
// Compute complex coordinates from pixel index
5783
double x = -X_DIM + i * x_step;
5884
double y = -Y_DIM + j * y_step;
5985

6086
// Compute the number of iterations
61-
auto iterations = compute_iterations({x, y}, constant, MAX_ITERATIONS);
87+
auto iterations = compute_iterations(constant, {x, y}, MAX_ITERATIONS);
6288

63-
// Draw the pixel
6489
display.set_pixel(
6590
i, j,
6691
static_cast<int>(iterations / static_cast<double>(MAX_ITERATIONS) * 255)
@@ -97,7 +122,7 @@ int main(int argc, char** argv)
97122
auto width = program.get<int>("width");
98123
auto height = program.get<int>("height");
99124

100-
display_julia(width, height, {1.0 / 4, 0});
125+
display_mandelbrot(width, height, {0, 0});
101126

102127
return 0;
103128
}

0 commit comments

Comments
 (0)