Skip to content

Commit

Permalink
gnuplot: remove flicker when redrawing
Browse files Browse the repository at this point in the history
  • Loading branch information
leonmavr committed Sep 15, 2024
1 parent 3b11258 commit b7e5619
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static float random_norm() {
return (float) random() / RAND_MAX;
}
static float accel = -5;
static int niters = 300;
static int niters = 600;

int main() {
srand(time(NULL));
Expand Down Expand Up @@ -56,9 +56,9 @@ int main() {
particles[ip].point.x %= boundary.x1;
particles[ip].point.y %= boundary.y1;
if (particles[ip].point.x <= boundary.x0)
particles[ip].point.x = boundary.x1 - 5;
particles[ip].point.x = boundary.x1;
if (particles[ip].point.y <= boundary.y0)
particles[ip].point.y = boundary.y1 - 5;
particles[ip].point.y = boundary.y1;
point_t pnew = {particles[ip].point.x , particles[ip].point.y, particles[ip].point.id};
node_insert(qtree.root, &pnew);
}
Expand Down
17 changes: 12 additions & 5 deletions src/viz.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,32 @@ void viz_init(unsigned width, unsigned height) {
ipoint = 0;
}


void viz_flush() {
fprintf(viz_plot_pipe, "clear\n");
// remove all previously drawn rectangles
for (int i = 0; i < irect; ++i) {
fprintf(viz_plot_pipe, "unset object %d\n", i + 1);
}
for (int i = 0; i < irect; ++i) {
fprintf(viz_plot_pipe, "set object %zu rect from %d,%d to %d,%d\n",
fprintf(viz_plot_pipe, "set object %d rect from %d,%d to %d,%d\n",
i + 1, viz_rects[i].x0, viz_rects[i].y0, viz_rects[i].x1, viz_rects[i].y1);
}
if (ipoint > 0) {
fprintf(viz_plot_pipe, "plot '-' with points pt 7 ps 1 title 'Points'\n");
for (int i = 0; i < ipoint; ++i)
fprintf(viz_plot_pipe, "plot '-' with points pt 7 ps 1\n");
for (int i = 0; i < ipoint; ++i) {
fprintf(viz_plot_pipe, "%d %d\n", viz_points[i].x, viz_points[i].y);
fprintf(viz_plot_pipe, "e\n"); // end the input
}
fprintf(viz_plot_pipe, "e\n"); // End the input
} else {
fprintf(stderr, "Warning: No points to plot.\n");
}
fprintf(viz_plot_pipe, "replot\n");
irect = ipoint = 0;
fflush(viz_plot_pipe);
usleep(16000);
}


void viz_write_rect(rect_t* rect) {
viz_rects[irect++] = *rect;
}
Expand Down

0 comments on commit b7e5619

Please sign in to comment.