diff --git a/charge.c b/charge.c index 20733aa2b8b9d5711354769dcf159ebc20af17ba..8f0d11466813e24099269167008006686094055a 100644 --- a/charge.c +++ b/charge.c @@ -47,4 +47,16 @@ void draw_charges(struct gfx_context_t *ctxt, charge_t *charges, int num_charges gfx_draw_circle(ctxt, chCoord, radius, charges[i].q < 0 ? COLOR_BLUE : COLOR_RED); } +} + +void generate_points(vec2 points[], int nb_points) { + double x = 0; + double y = 0; + + for (int i = 0; i < nb_points; i++) { + x = rand_one(); + y = rand_one(); + + points[i] = init_vector(x, y); + } } \ No newline at end of file diff --git a/charge.h b/charge.h index 07af84c9cbe685c22434a92525998a91415912de..a0bef2946d80ee5d7331f02a4503fcebf2b42bb1 100644 --- a/charge.h +++ b/charge.h @@ -76,4 +76,12 @@ bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, void draw_charges(struct gfx_context_t *ctxt, charge_t *charges, int num_charges, double x0, double x1, double y0, double y1); +/** + * @brief Generate a given amount of points + * + * @param points Points array + * @param nb_points Number of point to generate + */ +void generate_points(vec2 points[], int nb_points); + #endif // _CHARGE_H_ \ No newline at end of file diff --git a/main.c b/main.c index f70c311adaa4a9450aa62b9cf7572935bb91ae0c..25ce0a11596769cce900bbf9c4b9cb4c189de5cb 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,7 @@ #define y0 0 // Minimal y of the universe #define y1 1 // Maximal y of the universe #define NB_CHARGES 2 +#define NB_POINTS 100 int main(void) { srand(time(NULL)); @@ -38,6 +39,13 @@ int main(void) { charges[1] = charge_create(-10, init_vector(0.75, 0.5)); draw_charges(ctxt, charges, NB_CHARGES, x0, x1, y0, y1); + vec2 points[NB_POINTS]; + generate_points(points, NB_POINTS); + for (int i = 0; i < NB_POINTS; i++) { + coordinates_t c = position_to_coordinates(WINDOW_WIDTH, WINDOW_HEIGHT, x0, x1, y0, y1, points[i]); + gfx_putpixel(ctxt, c.column, c.row, COLOR_WHITE); + } + // GFX Draw loop while (gfx_keypressed() != SDLK_ESCAPE){ gfx_present(ctxt);