1
1
#pragma once
2
2
3
+ #include " config.hpp"
3
4
#include " graphics/aspect_ratio/aspect_ratio.hpp"
4
5
#include " graphics/color_conversions/color_conversions.hpp"
5
6
#include " graphics/display_event_observer.hpp"
@@ -33,6 +34,18 @@ class Window : public DisplayEventObserver {
33
34
);
34
35
}
35
36
37
+ void
38
+ set_pixel_colors (std::unique_ptr<MandelbrotWindow::pixel_iteration_counts> pixels)
39
+ {
40
+ for (auto it = DISPLAY_DOMAIN.begin (); it != DISPLAY_DOMAIN.end (); ++it) {
41
+ Percentage color (
42
+ static_cast <float >((*pixels)[it.get_underlying ()])
43
+ / MANDELBROT_MAX_ITERATIONS
44
+ );
45
+ set_pixel_color (*it, color);
46
+ }
47
+ }
48
+
36
49
Window (DisplayDomain display_domain, complex_domain complex_domain) :
37
50
DISPLAY_DOMAIN{display_domain}, complex_domain_{complex_domain},
38
51
mandelbrot_{display_domain, complex_domain}
@@ -42,10 +55,7 @@ class Window : public DisplayEventObserver {
42
55
display_domain.get_end_coordinate ().y + 1u
43
56
);
44
57
45
- auto res = mandelbrot_.calculate_ (DISPLAY_DOMAIN, DISPLAY_DOMAIN);
46
- for (display_coordinate pos : DISPLAY_DOMAIN) {
47
- set_pixel_color (pos, (*res)[pos.x ][pos.y ]);
48
- }
58
+ set_pixel_colors (mandelbrot_.calculate_ (DISPLAY_DOMAIN, DISPLAY_DOMAIN));
49
59
}
50
60
51
61
void on_mouse_button_pressed (const sf::Event::MouseButtonEvent& event) override
@@ -60,10 +70,7 @@ class Window : public DisplayEventObserver {
60
70
DisplayDomain ends = calculate_rectangle_end_points (
61
71
{selection_start_x_, selection_start_y_}, {event.x , event.y }
62
72
);
63
- auto res = mandelbrot_.calculate_ (DISPLAY_DOMAIN, ends);
64
- for (display_coordinate pos : DISPLAY_DOMAIN) {
65
- set_pixel_color (pos, (*res)[pos.x ][pos.y ]);
66
- }
73
+ set_pixel_colors (mandelbrot_.calculate_ (DISPLAY_DOMAIN, ends));
67
74
}
68
75
69
76
std::optional<std::unique_ptr<sf::Drawable>> get_drawable () override
0 commit comments