Skip to content
Snippets Groups Projects
Verified Commit cd5fc63c authored by orestis.malaspin's avatar orestis.malaspin
Browse files

visualization cooler a bit. but still not great

parent 24f1ec05
No related branches found
No related tags found
No related merge requests found
Pipeline #12982 passed
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
......
......@@ -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) {
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment