lnvis

nanovg lightning network visualizer
git clone git://jb55.com/lnvis
Log | Files | Refs | README | LICENSE

commit 523f7641666ede528901bf0f7fc475762a724375
parent 353c6cfeee1e6c1ed4eb1508161fbd270e2f9792
Author: William Casarin <jb55@jb55.com>
Date:   Sat,  4 Aug 2018 19:54:29 -0700

fixes

Diffstat:
Mmain.c | 7+++++--
Mupdate.c | 17++++++++++-------
2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/main.c b/main.c @@ -79,6 +79,8 @@ void random_network(int ww, int wh, int max_per_node, int num_nodes, struct ln * ln->node_count = num_nodes; ln->channels = malloc(sizeof(*ln->channels) * num_nodes * max_per_node); + printf("max channels %d\n", num_nodes * max_per_node); + for (i = 0; i < num_nodes; ++i) { n = &ln->nodes[i]; @@ -99,10 +101,10 @@ void random_network(int ww, int wh, int max_per_node, int num_nodes, struct ln * // connect nodes randomly for (i = 0; i < num_nodes; ++i) { + from = i; skip: // for each node, it can have 0 to max_per_node connections for (j = 0; j < rand() % max_per_node; ++j) { - from = i; do { tries++; if (tries > 5) { @@ -243,7 +245,8 @@ int main() if (first) { - random_network(winWidth, winHeight, 3, 100, &ln); + random_network(winWidth, winHeight, 3, 50, &ln); + printf("channels %d\n", ln.channel_count); first = 0; } diff --git a/update.c b/update.c @@ -68,8 +68,11 @@ void update(struct ln *ln, double dt) double nnx = (d - mindist) * nx; double nny = (d - mindist) * ny; - double mx = nnx; - double my = nny; + if (isnan(nnx) || isnan(nny)) + continue; + + double mx = nnx * dt; + double my = nny * dt; n1->vx += mx; n1->vy += my; @@ -78,13 +81,13 @@ void update(struct ln *ln, double dt) n2->vy -= my; } else { - const double scale = 0.01; + const double scale = 1.0; - n1->vx += dx * scale; - n1->vy += dy * scale; + n1->vx += dx * scale * dt; + n1->vy += dy * scale * dt; - n2->vx += -dx * scale; - n2->vy += -dy * scale; + n2->vx += -dx * scale * dt; + n2->vy += -dy * scale * dt; } }