diff --git a/travaux_pratiques/tpChaos/Makefile b/travaux_pratiques/tpChaos/Makefile index e5cf4aef323bd3cd9e15cf55b16614fbc15dd034..0dc6aae930eec4712c3d264a170368d18338272c 100644 --- a/travaux_pratiques/tpChaos/Makefile +++ b/travaux_pratiques/tpChaos/Makefile @@ -1,5 +1,6 @@ CC=gcc -CFLAGS=-Wall -Wextra -pedantic -std=c11 -g -fsanitize=leak -fsanitize=undefined -fsanitize=address -O3 +CFLAGS=-Wall -Wextra -pedantic -std=c11 -g -O3 +# -fsanitize=leak -fsanitize=undefined -fsanitize=address LFLAGS=-lSDL2 TARGET=map diff --git a/travaux_pratiques/tpChaos/map.c b/travaux_pratiques/tpChaos/map.c index 525d25451e4c1ff1303dae68cbba6b4920c7fcfa..2f0bbe39f9b46d884fde375d641f41db19262ae4 100644 --- a/travaux_pratiques/tpChaos/map.c +++ b/travaux_pratiques/tpChaos/map.c @@ -3,16 +3,24 @@ #include <unistd.h> #include "gfx.h" -double map(double x, double lambda) { +static void gfx_clear_rect(struct gfx_context_t *ctxt, int x0, int x1, int y0, int y1) { + for (int x = x0; x < x1; ++x) { + for (int y = y0; y < y1; ++y) { + gfx_putpixel(ctxt, x, y, COLOR_BLACK); + } + } +} + +static double map(double x, double lambda) { return lambda * x * (1.0 - x); } int main() { - const double lambda_min = 0; + const double lambda_min = 3; const double lambda_max = 4; const int N = 1920; - const int M = 960; - const double dl = (lambda_max - lambda_min) / N; + const int M = 1000; + double dl = (lambda_max - lambda_min) / N; struct gfx_context_t *ctxt = gfx_create("Example", N, M); if (!ctxt) { @@ -20,25 +28,38 @@ int main() { return EXIT_FAILURE; } gfx_clear(ctxt, COLOR_BLACK); + + double prop = 0.2; + int num_points = M / 10; - int max_iter = 100000; - for (double i_lambda = 0; i_lambda < N; ++i_lambda) { + int max_iter = 10000; + for (int i_lambda = 0; i_lambda < N; ++i_lambda) { double x = 0.5; for (int i = 0; i < max_iter; ++i) { double lambda = lambda_min + i_lambda * dl; - double x_new = map(x, lambda); - x = x_new; - if (i > max_iter - M) { - gfx_putpixel(ctxt, i_lambda, M - x * M - 1, COLOR_WHITE); + x = map(x, lambda); + if (i > max_iter - num_points) { + gfx_putpixel(ctxt, i % (num_points / 2), (M - 1) - (M - 1) * x * prop, COLOR_WHITE); + gfx_clear_rect(ctxt, (i + 1) % (num_points / 2), (i + 2) % (num_points / 2), (1 - prop) * (M-1), (M - 1)); + + gfx_putpixel(ctxt, i_lambda, (M - 1) * (1 - x), COLOR_WHITE); // printf("x(%d, %g) = %g\n", i, i_lambda * dl, x); // usleep((unsigned int)1000); + + // if (i % 512 == 0) { + // gfx_present(ctxt); + // } + } + } + gfx_clear_rect(ctxt, (num_points / 2 - 1), (num_points / 2) + 2, (1 - prop) * (M-1), (M - 1)); gfx_present(ctxt); // printf("\n"); } + while (gfx_keypressed() != SDLK_ESCAPE) { }