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

Added heatmap

parent aa8f8653
......@@ -25,13 +25,30 @@
#define X_CHARGE_2 0.6
#define Y_CHARGE_2 0.5
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
int32_t SDL_SpawnAll(SDL_Window ** pp_win_, SDL_Renderer ** pp_ren);
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 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;
}
int main()
{
srand(time(NULL));
// ! CREATE EMPTY SDL STUFF
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;
......@@ -49,15 +66,44 @@ int main()
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;
charges[1].q = -1.6E-19;
// DRAW
// GFX_ClearScreen(renderer, COLOR_BLACK);
double heatmap[WIDTH][HEIGHT];
double min = 1000000, max = 0;
for (uint32_t x = 0; x < WIDTH; x++)
{
for (uint32_t y = 0; y < HEIGHT; y++)
{
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 (tmp < min) {min = tmp;}
if (tmp > max) {max = tmp;}
heatmap[x][y] = tmp;
}
}
for (uint32_t x = 0; x < WIDTH; x++)
{
for (uint32_t y = 0; y < HEIGHT; y++)
{
GFX_DrawPixel(renderer, x, y, rgb(min, max, heatmap[x][y]), 1);
}
}
// DESSINE LES CHARGES
draw_charges(renderer, charges, 2, 10);
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};
......
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