Skip to content

Commit

Permalink
Window maj
Browse files Browse the repository at this point in the history
  • Loading branch information
angeluriot committed Jan 21, 2020
1 parent fb19758 commit 3824e13
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 51 deletions.
13 changes: 2 additions & 11 deletions includes/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,9 @@
#include <windows.h>
#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
4 changes: 2 additions & 2 deletions includes/fractal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 4 additions & 25 deletions sources/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.)));

Expand All @@ -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);
}
}
20 changes: 10 additions & 10 deletions sources/fractal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;

Expand All @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions sources/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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



// ---------------------------------------------------------------------------
Expand All @@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit 3824e13

Please sign in to comment.