Skip to content
Snippets Groups Projects
Commit d140ffbc authored by Tanguy Cavagna's avatar Tanguy Cavagna
Browse files

File reorder

parent 9b987a33
Branches
No related tags found
No related merge requests found
Pipeline #14863 failed
......@@ -8,21 +8,25 @@
* @copyright Copyright (c) 2021
*
*/
#include "draw/draw.h"
#include "vector/vector.h"
#include "utils.h"
#include "../draw/draw.h"
#include "../vector/vector.h"
#include "../utilities/utils.h"
#include "charge.h"
bool compute_e(charge_t c, vec2 p, double eps, vec2 *e) {
bool compute_e(charge_t c, vec2 p, double eps, vec2 *e)
{
}
bool compute_total_normalized_e(charge_t *charges, int num_charges, vec2 p, double eps, vec2 *e) {
bool compute_total_normalized_e(charge_t *charges, int num_charges, vec2 p, double eps, vec2 *e)
{
}
bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int num_charges, double dx, vec2 pos0, double x0, double x1, double y0, double y1) {
bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int num_charges, double dx, vec2 pos0, double x0, double x1, double y0, double y1)
{
}
void draw_charges(struct gfx_context_t *ctxt, charge_t *charges, int num_charges, double x0, double x1, double y0, double y1) {
void draw_charges(struct gfx_context_t *ctxt, charge_t *charges, int num_charges, double x0, double x1, double y0, double y1)
{
// Center coordinates
coordinates_t c;
......@@ -34,13 +38,17 @@ void draw_charges(struct gfx_context_t *ctxt, charge_t *charges, int num_charges
int chargePadding = 10;
// Draw charges
for (int i = 0; i < num_charges; i++) {
for (int i = 0; i < num_charges; i++)
{
coordinates_t chCoord = position_to_coordinates(ctxt->width, ctxt->height, x0, x1, y0, y1, charges[i].pos);
// Draw sign according to charge value
if (charges[i].q < 0) {
if (charges[i].q < 0)
{
gfx_draw_line(ctxt, coordinates_create(chCoord.row, chCoord.column - chargePadding), coordinates_create(chCoord.row, chCoord.column + chargePadding), COLOR_BLUE);
} else {
}
else
{
gfx_draw_line(ctxt, coordinates_create(chCoord.row, chCoord.column - chargePadding), coordinates_create(chCoord.row, chCoord.column + chargePadding), COLOR_RED);
gfx_draw_line(ctxt, coordinates_create(chCoord.row - chargePadding, chCoord.column), coordinates_create(chCoord.row + chargePadding, chCoord.column), COLOR_RED);
}
......@@ -49,11 +57,13 @@ void draw_charges(struct gfx_context_t *ctxt, charge_t *charges, int num_charges
}
}
void generate_points(vec2 points[], int nb_points) {
void generate_points(vec2 points[], int nb_points)
{
double x = 0;
double y = 0;
for (int i = 0; i < nb_points; i++) {
for (int i = 0; i < nb_points; i++)
{
x = rand_one();
y = rand_one();
......
......@@ -13,9 +13,9 @@
#include <stdlib.h>
#include <stdbool.h>
#include "utils.h"
#include "vector/vector.h"
#include "gfx/gfx.h"
#include "../utilities/utils.h"
#include "../vector/vector.h"
#include "../gfx/gfx.h"
/**
* @brief Compute E*qP/norm(qP)
......@@ -38,7 +38,7 @@ bool compute_e(charge_t c, vec2 p, double eps, vec2 *e);
* @param e Electric field
* @return bool false for some qiP, norm(qiP) < eps
*/
bool compute_total_normalized_e(charge_t *charges, int num_charges, vec2 p,
bool compute_total_normalized_e(charge_t *charges, int num_charges, vec2 p,
double eps, vec2 *e);
/**
......@@ -56,9 +56,9 @@ bool compute_total_normalized_e(charge_t *charges, int num_charges, vec2 p,
* @param y1 Maximal y of the universe
* @return bool false if pos0 not a valid pos (e.g. too close to a charge)
*/
bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges,
int num_charges, double dx, vec2 pos0, double x0,
double x1, double y0, double y1);
bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges,
int num_charges, double dx, vec2 pos0, double x0,
double x1, double y0, double y1);
/**
* @brief Draw all charges
......@@ -74,7 +74,7 @@ bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges,
* @param y1 Maximal y of the universe
*/
void draw_charges(struct gfx_context_t *ctxt, charge_t *charges,
int num_charges, double x0, double x1, double y0, double y1);
int num_charges, double x0, double x1, double y0, double y1);
/**
* @brief Generate a given amount of points
......
......@@ -13,7 +13,7 @@
#include <time.h>
#include <math.h>
#include "gfx/gfx.h"
#include "charge.h"
#include "charge/charge.h"
#define WINDOW_WIDTH 500
#define WINDOW_HEIGHT 500
......@@ -24,12 +24,14 @@
#define NB_CHARGES 2
#define NB_POINTS 100
int main(void) {
int main(void)
{
srand(time(NULL));
// GFX initialization
struct gfx_context_t *ctxt = gfx_create("draw", WINDOW_WIDTH, WINDOW_HEIGHT);
if (!ctxt) {
if (!ctxt)
{
fprintf(stderr, "Graphics initialization failed !\n");
return EXIT_FAILURE;
}
......@@ -41,13 +43,15 @@ int main(void) {
vec2 points[NB_POINTS];
generate_points(points, NB_POINTS);
for (int i = 0; i < NB_POINTS; i++) {
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){
while (gfx_keypressed() != SDLK_ESCAPE)
{
gfx_present(ctxt);
}
......
#include <math.h>
#include <stdlib.h>
#include "vector/vector.h"
#include "../vector/vector.h"
#include "utils.h"
// Transform a position in the univers [x0,y0]x[x1,y1] to a screen position
......
......@@ -5,8 +5,8 @@
#define E 1.602e-19;
#include <stdint.h>
#include "vector/vector.h"
#include "draw/draw.h"
#include "../vector/vector.h"
#include "../draw/draw.h"
typedef struct _charge_t
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment