Commit bf01e8e6 authored by nicolas.albanesi's avatar nicolas.albanesi
Browse files

Added heatmap and switchcase

parent cd6e75dc
......@@ -22,7 +22,7 @@
// #define Y_CHARGE_1 HEIGHT/2
#define X_CHARGE_1 0.3
#define Y_CHARGE_1 0.5
#define X_CHARGE_2 0.6
#define X_CHARGE_2 0.7
#define Y_CHARGE_2 0.5
#define MIN(a,b) (((a)<(b))?(a):(b))
......@@ -33,45 +33,15 @@ void SDL_killAll(SDL_Window ** pp_win_, SDL_Renderer ** pp_ren);
uint32_t rgb(double minimum, double maximum, double value)
{
// maximum = maximum / 1000;
maximum = 75;
double ratio = 2 * (value - minimum) / (maximum - minimum);
double ratio = 4 * (value - minimum) / (maximum - minimum);
double b = MAX(0.0, (255.0 * (1.0 - ratio)));
double r = MAX(0.0, (255.0 * (ratio - 1.0)));
int g = 255 - b - r;
return (int)(r)<<16 | g<<8 | (int)(b);
return g;
uint32_t g = 255 - b - r;
return (uint32_t)(r)<<16 | g<<8 | (uint32_t)(b);
}
int main()
void draw_heatmap(SDL_Renderer* renderer, charge_t* charges)
{
srand(time(NULL));
// ! CREATE EMPTY SDL STUFF
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;
bool running_loop = true;
SDL_Event event;
if( SDL_SpawnAll(&window, &renderer) == 0 )
{
printf("SDL STUFF SUCCESSFULLY SPAWNED!\n");
}
// ! INIT CHARGES
charge_t *charges = malloc(2 * sizeof(*charges));
charges[0].pos = (vec2){X_CHARGE_1, Y_CHARGE_1};
charges[0].q = 1.6E-19;
charges[1].pos = (vec2){X_CHARGE_2, Y_CHARGE_2};
charges[1].q = -1.6E-19;
// DRAW
// GFX_ClearScreen(renderer, COLOR_BLACK);
double heatmap[WIDTH][HEIGHT];
double min = 1000000, max = 0;
......@@ -81,14 +51,16 @@ int main()
{
vec2 e = {.x = 0, .y = 0};
vec2 p = {.x = x / 500.0, .y = y / 500.0};
compute_total_normalized_e(charges, 2, p, 0.025, &e);
e = vec2_mul(1E9, e);
double tmp = vec2_norm(e);
if (compute_total_normalized_e(charges, 2, p, 0.05, &e))
{
e = vec2_mul(1E9, e);
double tmp = vec2_norm(e);
if (tmp < min) {min = tmp;}
if (tmp > max) {max = tmp;}
heatmap[x][y] = tmp;
if (tmp < min) {min = tmp;}
if (tmp > max) {max = tmp;}
heatmap[x][y] = tmp;
}
else {heatmap[x][y] = 0;}
}
}
......@@ -96,14 +68,23 @@ int main()
{
for (uint32_t y = 0; y < HEIGHT; y++)
{
GFX_DrawPixel(renderer, x, y, rgb(min, max, heatmap[x][y]), 1);
double val = heatmap[x][y];
if (val != 0)
{
GFX_DrawPixel(renderer, x, y, rgb(min, max, val), 1);
}
else
{
GFX_DrawPixel(renderer, x, y, COLOR_BLACK, 1);
}
}
}
// DESSINE LES CHARGES
draw_charges(renderer, charges, 2, 10);
}
void draw_lines(SDL_Renderer* renderer, charge_t* charges)
{
for (int i = 0; i < 100; i++)
{
vec2 p = {.x = (double)(rand() % 10)/10.0+0.01 , .y = (double)(rand() % 10)/10.0+0.01};
......@@ -148,6 +129,40 @@ int main()
p = next_p;
}
}
}
int main()
{
srand(time(NULL));
// ! CREATE EMPTY SDL STUFF
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;
bool running_loop = true;
SDL_Event event;
if( SDL_SpawnAll(&window, &renderer) == 0 )
{
printf("SDL STUFF SUCCESSFULLY SPAWNED!\n");
}
// ! INIT CHARGES
charge_t *charges = malloc(2 * sizeof(*charges));
charges[0].pos = (vec2){X_CHARGE_1, Y_CHARGE_1};
charges[0].q = 1.6E-19;
charges[1].pos = (vec2){X_CHARGE_2, Y_CHARGE_2};
charges[1].q = -1.6E-19;
// DRAW
// GFX_ClearScreen(renderer, COLOR_BLACK);
draw_heatmap(renderer, charges);
// DESSINE LES CHARGES
// while (p.x < 1.0 && p.x > 0 && p.y < 1.0 && p.y > 0)
......@@ -170,11 +185,12 @@ int main()
// p = next_p;
// }
SDL_RenderPresent(renderer);
while(running_loop)
// ! FAIRE UN ENUM POUR LE STATE
int state = 1;
while (running_loop)
{
while(SDL_PollEvent(&event))
{
......@@ -186,8 +202,33 @@ int main()
case SDLK_ESCAPE: // QUIT ON ESCAP
running_loop = false;
break;
case SDLK_h:
state = 2;
break;
case SDLK_l:
state = 1;
break;
}
}
switch (state)
{
case 0: // IDLE
break;
case 1: // LINES
GFX_ClearScreen(renderer, COLOR_BLACK);
draw_lines(renderer, charges);
draw_charges(renderer, charges, 2, 10);
SDL_RenderPresent(renderer);
state = 0;
break;
case 2: // HEATMAP
draw_heatmap(renderer, charges);
draw_charges(renderer, charges, 2, 10);
SDL_RenderPresent(renderer);
state = 0;
break;
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment