Skip to content

Commit

Permalink
Merge pull request #101 from edgar-bonet/loop-modulo
Browse files Browse the repository at this point in the history
Remove code repetition from `plot_values()`
  • Loading branch information
tenox7 authored Nov 23, 2023
2 parents 8d24130 + c43fb20 commit 5495aec
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions ttyplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,13 @@ void draw_line(int x, int ph, int l1, int l2, chtype c1, chtype c2, chtype hce,
}

void plot_values(int ph, int pw, double *v1, double *v2, double max, double min, int n, chtype pc, chtype hce, chtype lce, double hm) {
int i;
int x=3;
const int first_col=3;
int i=(n+1)%pw;
int x;
max-=min;

for(i=n+1; i<pw; i++)
draw_line(x++, ph,
(v1[i]>hm) ? ph : (v1[i]<min) ? 1 : (int)(((v1[i]-min)/max)*(double)ph),
(v2[i]>hm) ? ph : (v2[i]<min) ? 1 : (int)(((v2[i]-min)/max)*(double)ph),
(v1[i]>hm) ? hce : (v1[i]<min) ? lce : pc,
(v2[i]>hm) ? hce : (v2[i]<min) ? lce : pc,
hce, lce);

for(i=0; i<=n; i++)
draw_line(x++, ph,
for(x=first_col; x<first_col+pw; x++, i=(i+1)%pw)
draw_line(x, ph,
(v1[i]>hm) ? ph : (v1[i]<min) ? 1 : (int)(((v1[i]-min)/max)*(double)ph),
(v2[i]>hm) ? ph : (v2[i]<min) ? 1 : (int)(((v2[i]-min)/max)*(double)ph),
(v1[i]>hm) ? hce : (v1[i]<min) ? lce : pc,
Expand Down

0 comments on commit 5495aec

Please sign in to comment.