From 0c71c3724f8a5bb0fb5aaf6170faa535cf8b32e5 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Thu, 21 Apr 2022 12:21:23 +0200 Subject: [PATCH] rv::som:: improved animation --- rogueviz/som/kohonen.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/rogueviz/som/kohonen.cpp b/rogueviz/som/kohonen.cpp index 5f548527..d466447b 100644 --- a/rogueviz/som/kohonen.cpp +++ b/rogueviz/som/kohonen.cpp @@ -1384,14 +1384,27 @@ void neurondisttable(const string &name) { fclose(f); } -bool animate = true; +bool animate_loop; +bool animate_once; void steps() { - if(kohonen::animate && !kohonen::finished()) { + if(kohonen::animate_once && !kohonen::finished()) { unsigned int t = SDL_GetTicks(); while(SDL_GetTicks() < t+20) kohonen::step(); setindex(false); } + if(kohonen::animate_loop) { + ld tfrac = frac(1 - ticks * 1. / anims::period); + int t1 = tmax * tfrac; + println(hlog, "got t1 = ", t1, "/", tmax); + if(t1 > t) { + initialize_rv(); + set_neuron_initial(); + t = tmax; + } + while(t > t1) kohonen::step(); + setindex(false); + } } void shift_color(int i) { @@ -1784,7 +1797,8 @@ auto hooks4 = addHook(hooks_clearmemory, 100, clear) -> editable(0, 2, .2, "precise placement", "0 = make all visible, 1 = place ideally, n = place 1/n of the distance from center to ideal placement", 'p') -> set_reaction([] { if((state & KS_NEURONS) && (state & KS_SAMPLES)) distribute_neurons(); }); param_b(show_rings, "som_show_rings"); - param_b(animate, "animate"); + param_b(animate_once, "som_animate_once"); + param_b(animate_loop, "som_animate_loop"); param_f(dispersion_precision, "som_dispersion") -> set_reaction([] { state &=~ KS_DISPERSION; }); });