From 3824e13487d2fce2952d914a17b0636d5222ed61 Mon Sep 17 00:00:00 2001 From: D1MENSI0N Date: Tue, 21 Jan 2020 23:24:52 +0100 Subject: [PATCH] Window maj --- includes/display.h | 13 ++----------- includes/fractal.h | 4 ++-- sources/display.cpp | 29 ++++------------------------- sources/fractal.cpp | 20 ++++++++++---------- sources/main.cpp | 9 ++++++--- 5 files changed, 24 insertions(+), 51 deletions(-) diff --git a/includes/display.h b/includes/display.h index 46c762f..ab86d38 100644 --- a/includes/display.h +++ b/includes/display.h @@ -3,18 +3,9 @@ #include #include "SDL.h" -#define HEIGHT 1080 // Hauteur de la fenêtre (en pixels) -#define WIDTH 1920 // Largeur de la fenêtre (en pixels) -#define DISPLAY_SIZE 800 // Taille de l'affichage (en pixels) -#define GAP_X 200 // Décalage en X (en pixels) -#define GAP_Y 100 // Décalage en Y (en pixels) -#define COLOR_CONSTANT 7. // Constante permettant d'améliorer les couleurs -#define SEQUENCE_MAX 10. // Le calcul de la suite s'arrête quand elle atteint cette valeur - extern SDL_Renderer* renderer; -void set_point(const int& x, const int& y, const COLORREF& color); -COLORREF color(int value, const int& max_value); -void contour(); +void set_point(const int& x, const int& y, const COLORREF& color, const int& window_size); +COLORREF color(int value, const int& max_value, const double& color_constant); #endif \ No newline at end of file diff --git a/includes/fractal.h b/includes/fractal.h index b50039e..2f529bf 100644 --- a/includes/fractal.h +++ b/includes/fractal.h @@ -5,7 +5,7 @@ enum Fractale_type { Julia, Mandelbrot }; // Type de fractale -int sequence(Complex z, const Complex& c, const int& iteration_nb); -void show_image(const double& p_x, const double& p_y, const double& graph_size, const int& iteration_nb, const Fractale_type& fractale_type, const Complex& c, SDL_Event& event); +int sequence(Complex z, const Complex& c, const int& iteration_nb, const double& sequences_max); +void show_image(const double& p_x, const double& p_y, const double& graph_size, const int& iteration_nb, const Fractale_type& fractale_type, const Complex& c, SDL_Event& event, const int& window_size, const double& color_constant, const double& sequences_max); #endif \ No newline at end of file diff --git a/sources/display.cpp b/sources/display.cpp index f803fdb..d238869 100644 --- a/sources/display.cpp +++ b/sources/display.cpp @@ -5,19 +5,19 @@ // Affiche un pixel aux coordonnées voulues -void set_point(const int& x, const int& y, const COLORREF& color) +void set_point(const int& x, const int& y, const COLORREF& color, const int& window_size) { SDL_SetRenderDrawColor(renderer, GetRValue(color), GetGValue(color), GetBValue(color), SDL_ALPHA_OPAQUE); - SDL_RenderDrawPoint(renderer, GAP_X + x, GAP_Y + DISPLAY_SIZE - y); + SDL_RenderDrawPoint(renderer, x, window_size - y); } // Donne une couleur à partir du temps que prend la suite à diverger -COLORREF color(int value, const int& max_value) +COLORREF color(int value, const int& max_value, const double& color_constant) { - value *= COLOR_CONSTANT; + value *= color_constant; value = int(double((double(value) / double(max_value)) * double(255. * 2.))); @@ -28,25 +28,4 @@ COLORREF color(int value, const int& max_value) return RGB(2 * 255 - value, 0, value - 255); return RGB(0, 0, 0); -} - - - -// Trace un contour blanc - -void contour() -{ - SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE); - - for (int i = 0; i < DISPLAY_SIZE; i++) - { - SDL_RenderDrawPoint(renderer, i + GAP_X, GAP_Y); - SDL_RenderDrawPoint(renderer, i + GAP_X, GAP_Y + DISPLAY_SIZE + 1); - } - - for (int j = 0; j < DISPLAY_SIZE + 2; j++) - { - SDL_RenderDrawPoint(renderer, GAP_X - 1, j + GAP_Y); - SDL_RenderDrawPoint(renderer, GAP_X + DISPLAY_SIZE, j + GAP_Y); - } } \ No newline at end of file diff --git a/sources/fractal.cpp b/sources/fractal.cpp index 23af780..f5b02d1 100644 --- a/sources/fractal.cpp +++ b/sources/fractal.cpp @@ -7,13 +7,13 @@ // Calcul la suite d'équation z = z² + c et renvoie le nombre d'itérations pour atteindre "sequence_max" -int sequence(Complex z, const Complex& c, const int& iteration_nb) +int sequence(Complex z, const Complex& c, const int& iteration_nb, const double& sequences_max) { for (int i = 0; i < iteration_nb; i++) { z = z * z + c; // L'équation - if (z.modulus() > SEQUENCE_MAX) + if (z.modulus() > sequences_max) return i; } @@ -24,19 +24,19 @@ int sequence(Complex z, const Complex& c, const int& iteration_nb) // Affiche l'image en entier de la forme fractale -void show_image(const double& p_x, const double& p_y, const double& graph_size, const int& iteration_nb, const Fractale_type& fractale_type, const Complex& c, SDL_Event& event) +void show_image(const double& p_x, const double& p_y, const double& graph_size, const int& iteration_nb, const Fractale_type& fractale_type, const Complex& c, SDL_Event& event, const int& window_size, const double& color_constant, const double& sequences_max) { double x = p_x - graph_size / 2.; double y = p_y - graph_size / 2.; - double x_pas = graph_size / double(DISPLAY_SIZE); - double y_pas = graph_size / double(DISPLAY_SIZE); + double x_pas = graph_size / double(window_size); + double y_pas = graph_size / double(window_size); - for (int i = 0; i < DISPLAY_SIZE; i++) + for (int i = 0; i < window_size; i++) { x = p_x - graph_size / 2; y += y_pas; - for (int j = 0; j < DISPLAY_SIZE; j++) + for (int j = 0; j < window_size; j++) { x += x_pas; @@ -45,17 +45,17 @@ void show_image(const double& p_x, const double& p_y, const double& graph_size, if (fractale_type == Julia) { Complex z = Complex(x, y); - sequence_result = sequence(z, c, iteration_nb); + sequence_result = sequence(z, c, iteration_nb, sequences_max); } else { Complex c = Complex(x, y); - sequence_result = sequence(Complex(0, 0), c, iteration_nb); + sequence_result = sequence(Complex(0, 0), c, iteration_nb, sequences_max); } if (sequence_result != iteration_nb) - set_point(j, i, color(sequence_result, iteration_nb)); + set_point(j, i, color(sequence_result, iteration_nb, color_constant), window_size); } SDL_RenderPresent(renderer); diff --git a/sources/main.cpp b/sources/main.cpp index 9e1d11f..2a2a59f 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -17,12 +17,16 @@ int main(int argc, char* argv[]) double x = -0.75; // Coordonnée x du centre de la vue double y = 0.; // Coordonnée y du centre de la vue + int window_size = 800; // Taille de la fenêtre (en pixels) double graph_size = 3.; // Taille de la vue (zoom) int iteration_nb = 250; // Nombre d'intérations de la suite (précision) Fractale_type fractale_type = Mandelbrot; // Type de fractale (Mandelbrot ou Julia) Complex c = Complex(-0.55, 0.55); // Valeur de c (pour Julia) + double color_constant = 7.; // Constante permettant d'améliorer les couleurs + double sequences_max = 10.; // Le calcul de la suite s'arrête quand elle atteint cette valeur + // --------------------------------------------------------------------------- @@ -34,7 +38,7 @@ int main(int argc, char* argv[]) window = NULL; renderer = NULL; - SDL_CreateWindowAndRenderer(WIDTH, HEIGHT, 0, &window, &renderer); + SDL_CreateWindowAndRenderer(window_size, window_size, 0, &window, &renderer); SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_ADD); SDL_SetWindowTitle(window, "Fractal generator"); SDL_Event event; @@ -44,8 +48,7 @@ int main(int argc, char* argv[]) SDL_RenderPresent(renderer); - contour(); - show_image(x, y, graph_size, iteration_nb, fractale_type, c, event); + show_image(x, y, graph_size, iteration_nb, fractale_type, c, event, window_size, color_constant, sequences_max); SDL_RenderPresent(renderer);