Skip to content
Snippets Groups Projects
Commit 6f3e264f authored by tanguy.cavagna's avatar tanguy.cavagna :desktop:
Browse files

Merge branch 'feature/point-cluster-draw' into 'master'

Added point cluster generation and representation (temp)

See merge request physics/electric-field!5
parents ae991ee7 af0cf6ab
Branches
Tags
1 merge request!5Added point cluster generation and representation (temp)
......@@ -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
......@@ -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
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment