-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.c
executable file
·103 lines (76 loc) · 2.38 KB
/
display.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "psim.h"
#include "util.h"
#include "init.h"
#include "display.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void vprintd(char* format, int indent, bool pad, va_list args) {
const int space = indent * INDENT_SIZE;
char s[MAX_LINE * 2];
vsnprintf(s, MAX_LINE * 2, format, args);
printr(' ', space);
printf("%s", s);
if(pad) printr('-', MAX_LINE - (strlen(s) + space));
}
void vprintdln(char* format, int indent, bool pad, va_list args) {
vprintd(format, indent, pad, args);
printf("\n");
}
void printd(char* format, int indent, bool pad, ...) {
va_list args;
va_start(args, pad);
vprintd(format, indent, pad, args);
va_end(args);
}
void printdln(char* format, int indent, bool pad, ...) {
va_list args;
va_start(args, pad);
vprintdln(format, indent, pad, args);
va_end(args);
}
void display_uverse(struct universe uverse, int indent) {
printdln("Universe - Instant: %d ", indent, true, uverse.instant);
for(int i = 0; i < uverse.pcount; i++) {
display_particle(&uverse.particles[i], indent + 1);
printf("\n");
}
printdln("", indent, true);
}
void display_particle(struct particle* p, int indent) {
printdln("Particle ", indent, true);
printdln("Mass: %.2f", indent + 1, false, p->mass);
printdln("Charge: %.2f", indent + 1, false, p->charge);
printf("\n");
int c = 0;
struct vector* forces[10];
for(int i = 0; i < MAX_FORCES; i++) {
if(!veq(p->forces[i], vc_zero)) {
c++;
forces[i] = &p->forces[i];
} else forces[i] = NULL;
}
printdln("Forces: %d/%d", indent + 1, false, c, MAX_FORCES);
for(int i = 0; i < MAX_FORCES; i++)
if(forces[i] != NULL)
display_vector(*forces[i], indent + 2);
printf("\n");
printd("Position\t: ", indent + 1, false);
display_vector(p->cstate.pos, indent + 2);
printd("Velocity\t: ", indent + 1, false);
display_vector(p->cstate.vel, indent + 2);
printd("Acceleration\t: ", indent + 1, false);
display_vector(p->cstate.acc, indent + 2);
}
void display_vector(struct vector v, int indent) {
printdln("X: %.2f Y: %.2f", indent, false, v.x, v.y);
}
void print_progress(long val, long max, int size) {
int full = ((float) (val * size)) / max;
printf("\r[ %ld / %ld ", val, max);
for(int i = 0; i < size; i++) {
printf(i <= full ? "#" : "-");
}
printf(" ]");
fflush(stdout);
}