diff --git a/src/field.c b/src/field.c index 5736d1d65fe7d737a96fd3c361f9ce238cd3183c..acb3b4ce7f4208a3650b9d5144d7f09eeb85ae66 100644 --- a/src/field.c +++ b/src/field.c @@ -1,7 +1,7 @@ -#include <math.h> #include <stdbool.h> #include <stdlib.h> +#include "draw.h" #include "field.h" #include "draw.h" #include "../utils/utils.h" @@ -9,6 +9,7 @@ #define SIGN_SIZE 10 #define CHARGE_R 25 + // Compute E*qP/norm(qP) // Return false if norm(qP) < eps /// qP = vectoriel(P-q) @@ -63,7 +64,7 @@ void draw_charges(struct gfx_context_t *context, charge_t *charges, int num_char coordinates_t sign_src = charge_center; coordinates_t sign_dst = charge_center; uint32_t sign_color = COLOR_RED; - if (charges[i].q > 0){ + if (charges[i].q > 0) { sign_color = COLOR_BLUE; sign_src.row -= SIGN_SIZE; sign_dst.row += SIGN_SIZE; @@ -77,3 +78,18 @@ void draw_charges(struct gfx_context_t *context, charge_t *charges, int num_char gfx_draw_line(context, sign_src, sign_dst, sign_color); } } + +void draw_everything( + struct gfx_context_t *ctxt, + charge_t *charges, + int num_charges, + int num_lines, + double dx, + double x0, double x1, + double y0, double y1) { + draw_charges(ctxt, charges, num_charges, x0, x1, y0, y1); + for (int i = 0; i < num_lines; ++i) { + vec2 pos0 = vec2_normalize(vec2_create(rand(), rand())); + draw_field_line(ctxt, charges, num_charges, dx, pos0, x0, x1, y0, y1); + } +} diff --git a/src/field.h b/src/field.h index 982c4fd0c0a52f515853269943726a2063dac5f2..422593307ee637ce521141394783f07765879f88 100644 --- a/src/field.h +++ b/src/field.h @@ -29,4 +29,13 @@ bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int num_char // A circle with a plus sign for positive charges void draw_charges(struct gfx_context_t *context, charge_t *charges, int num_charges, double x0, double x1, double y0, double y1); +void draw_everything( + struct gfx_context_t *ctxt, + charge_t *charges, + int num_charges, + int num_lines, + double dx, + double x0, double x1, + double y0, double y1); + #endif diff --git a/src/main.c b/src/main.c index f3b87772390a8af46598652b58b7d691db3de9da..652462d384358f7fa28769505edc83bb6f5b5bfe 100644 --- a/src/main.c +++ b/src/main.c @@ -1,12 +1,15 @@ #include <stdlib.h> #include <time.h> + #include "draw.h" +#include "field.h" #include "../utils/utils.h" #include "field.h" #define NCHARGES 2 #define DX 0.0005 -#define NPOINTS 32 +#define NLINES 32 + int main() { srand(time(NULL)); @@ -18,7 +21,7 @@ int main() { draw_charges(ctxt, charges, NCHARGES, 0.0, 1.0, 0.0, 1.0); - for (int i = 0; i < NPOINTS; ++i) { + for (int i = 0; i < NCHARGES; ++i) { vec2 start = vec2_normalize(vec2_create(rand(), rand())); draw_field_line(ctxt, charges, NCHARGES, DX, start, 0.0, 1.0, 0.0, 1.0); }