Skip to content
Snippets Groups Projects
Commit 8a3e4543 authored by Boris Stefanovic's avatar Boris Stefanovic
Browse files

FIX: frame edge space and refresh loop for moving window around

parent d7b34e78
No related branches found
No related tags found
No related merge requests found
......@@ -3,3 +3,4 @@ build
*.o
*.pdf
main
*_tests
#include <stdbool.h>
#include "../utils/gfx/gfx.h"
#include "field.h"
#include "../utils/utils.h"
void gfx_draw_line(struct gfx_context_t *ctxt, coordinates_t p0, coordinates_t p1, uint32_t color) {
int dx = abs((int) p1.column - (int) p0.column);
......@@ -34,7 +34,8 @@ void gfx_draw_line(struct gfx_context_t *ctxt, coordinates_t p0, coordinates_t p
}
}
void gfx_draw_circle(struct gfx_context_t *ctxt, coordinates c, uint32_t r, uint32_t color) {
void gfx_draw_circle(struct gfx_context_t *ctxt, coordinates_t c, uint32_t r, uint32_t color) {
int x = 0;
int y = r;
int d = r - 1;
......
......@@ -3,7 +3,10 @@
#include "field.h"
void gfx_draw_line(struct gfx_context_t *ctxt, coordinates_t p0, coordinates_t p1, uint32_t color);
void gfx_draw_circle(struct gfx_context_t *ctxt, coordinates_t c, uint32_t r, uint32_t color);
#endif
......@@ -34,8 +34,7 @@ double compute_delta_x() {
}
bool is_in_screen(coordinates_t pos) {
// TODO: should this not be "<" instead of "<=" ?
return pos.column <= WID && pos.row <= HEI;
return pos.column < WID && pos.row < HEI;
}
bool draw_field_line_point(struct gfx_context_t *ctxt, charge_t *charges, int num_charges, double x0, double x1, double y0, double y1, vec2 pos, vec2 *pos_next, double delta) {
......@@ -105,7 +104,7 @@ static bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int n
/// A circle with minus sign for negative charges
/// A circle with a plus sign for positive charges
static void draw_charges(struct gfx_context_t *context, charge_t *charges, int num_charges, double x0, double x1, double y0, double y1) {
for (int i = 0; i < num_charges; i++) {
for (int i = 0; i < num_charges; ++i) {
coordinates_t charge_center = position_to_coordinates(WID, HEI, x0, x1, y0, y1, charges[i].pos);
gfx_draw_circle(context, charge_center, CHARGE_R, COLOR_WHITE);
......
......@@ -2,9 +2,9 @@
#define _PHYSIQUE_H_
#include <stdio.h>
#include "../utils/utils.h"
#include "../utils/gfx/gfx.h"
#include "../utils/vec2/vec2.h"
#include "../utils/utils.h"
#define SIDE_LEN 1000
#define WID SIDE_LEN
......
#include <stdlib.h>
#include <time.h>
#include "draw.h"
#include "field.h"
#include "../utils/utils.h"
#include "field.h"
#define NCHARGES 2
#define NC 3
#define DX 25
#define NLINES 50
int main() {
void main_old() {
charge_t charges[NCHARGES] = {
charge_create(0.25, vec2_create(0.25, 0.5)),
charge_create(-0.25, vec2_create(0.75, 0.5))
......@@ -23,5 +20,25 @@ int main() {
while (gfx_keypressed() != SDLK_ESCAPE);
gfx_destroy(ctxt);
}
void main_new() {
charge_t charges[NC];
for (int i = 0; i < NC; ++i)
charges[i] = charge_create(i % 2 == 0 ? rand_one() : -rand_one(), vec2_create(rand_one(), rand_one()));
struct gfx_context_t *ctxt = gfx_create("elec", WID, HEI);
draw_everything(ctxt, charges, NC, NLINES, DX, 0.0, 1.0, 0.0, 1.0);
gfx_present(ctxt);
while (gfx_keypressed() != SDLK_ESCAPE) {
gfx_present(ctxt);
}
gfx_destroy(ctxt);
}
int main() {
main_new();
return EXIT_SUCCESS;
}
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include "utils.h"
#include "vec2/vec2.h"
#include "utils.h"
coordinates_t coordinates_create(int row_, int column_) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment